Having the strangest Spring problem where after a Spring bean is created using Dependency Injection, and then running some method on the bean, the instance variables that are set during the bean method call all return to their default Java values. Found this happening after we moved from Spring 2.5.5 to Spring 3.0.5.
So for clarity sake here is the example
The Prototype bean:
@Component("bean1")
@Scope("prototype")
public class Bean1{
String someString;//There are other instance variables but same happens to them
@Autowired
@Qualifier("otherBean")
private OtherBean otherBean;
public void doSomething(){
someString="1234ABC";
}
//setters and getters ....
}
And the code that grabs the bean from spring and uses it:
Bean1 bean1 = (Bean1) applicationContext.getBean("bean1");
bean1.doSomething();//updates some instance variables in bean1
String value = bean1.getSomeString(); //Instance variables is null
Object otherObject = bean1.getOtherBean(); //This Spring injected bean is correctly initialized
So if I debug into the code, the instance variables (someString) is set in bean while in the doSomething method call but right after I return, the value goes back to null.
Worst thing is that this all works as expected in 2.5.5 but not in the updated Spring 3.0.5
This is legacy code so I know that you are supposed to code to interfaces and so the Bean1 should be an interface and the class that implements the interface should do the actual work. I changed the code to this model as well and still does not work.