Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6978501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:45:55+00:00 2026-05-27T17:45:55+00:00

There was method setWrappedInstance in org.springframework.beans.BeanWrapper in 2.5.6 and was removed in 3.0.0. As

  • 0

There was method setWrappedInstance in org.springframework.beans.BeanWrapper in 2.5.6 and was removed in 3.0.0. As i am in the process of migrating my project from 2.5 to 3.0 I get errors. I investigated and the implementation class org.springframework.beans.BeanWrapperImpl still has the method setWrappedInstance implemented.

below is the piece of code from my project which is causing trouble.

public FieldComparator(String fieldName, Class clazz) {
    _fieldName = fieldName;
    _bw = new BeanWrapperImpl(clazz);
}    

public int compare(Object o1, Object o2) {
    if (o1 == null && o2 == null) return 0;
    else if (o1 == null) return -1;
    else if (o2 == null) return 1;
    // otherwise
    _bw.setWrappedInstance(o1);
    Comparable v1 = (Comparable) _bw.getPropertyValue(_fieldName);

    _bw.setWrappedInstance(o2);
    Comparable v2 = (Comparable) _bw.getPropertyValue(_fieldName);
    return NullsLowComparator.INSTANCE.compare(v1, v2);
}

So would it be ok if I just replace _bw implementation with BeanWrapperImpl. I am in the learning stage and I believe that spring strongly suggests to use interfaces rather than implementation classes itself.

Is this change against standard practices or can I just move on with the simple change?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:45:56+00:00Added an answer on May 27, 2026 at 5:45 pm

    The BeanWrapper.setWrappedInstance method was marked as deprecated in Spring 2.5, and removed altogether in 3.0. Unlike deprecations in the JRE (which never get removed), deprecated APIs in Spring do get removed, so you’re well advised to avoid them.

    The 2.5.6 Javadoc for setWrappedInstance says:

    Deprecated. as of Spring 2.5, in favor of recreating a BeanWrapper per target instance

    In other words, instead of reusing instances of BeanWrapper, you should create new BeanWrapperImpl instances as required. There’s no performance penalty for this – the BeanWrapperImpl javadoc says that it “Caches introspection results for efficiency.”

    So replace this:

    _bw.setWrappedInstance(o1);
    Comparable v1 = (Comparable) _bw.getPropertyValue(_fieldName);
    

    with this:

    Comparable v1 = (Comparable) new BeanWrapperImpl(o1).getPropertyValue(_fieldName);
    

    and get rid of the _bw field altogether.

    I believe that spring strongly suggests to use interfaces rather than implementation classes itself

    As a general rule of thumb, yes. However, try to apply some practicality to this. Your use of BeanWrapperImpl is restricted entirely to internal implementation detail of your comparator, so there’s no real harm in using it directly. If your comparator were to expose the BeanWrapper in a public method signature, for some reason, then that would be best done using the interface rather than the implementation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any method to get the 3 char code from System.TimeZoneInfo.Local ? e.g.
Is there a method to get all of the .aspx files in my website?
Is there a method to launch an Internet Explorer window from a desktop Icon
Is there any method to populate a dataGridView on a form from another class?
Is there a method to stop lapply() from returning NULL values for each element
Is there any method within Perl which would allow me to get the object
Is there any method to use to save data from webpage to excel file
Is there any method with which I can get to know which of the
Is there any method in HTML or PHP to force-trigger specific HTTP 1.1 errors,
Is there a method to extract the area, controller, action, and querystring from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.