-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Description
Stefan Schmidt opened SPR-5790 and commented
AbstractBeanFactory.getBean(String name, Object [] args) does not work in conjunction with AbstractBeanFactory.getBean(String name).
Steps to replicate:
public class Test {
public Test() {
System.out.println("default constructor called");
}
public Test(String test) {
System.out.println("custom constructor called " + test);
}
}
<bean class="Test" scope="prototype" id="test" />
public class Main {
public static void main(String[] args) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
System.out.println(applicationContext.getBean("test", new Object[]{"test 1"}));
//comment this out and it will perform as expected, move it one line up and the argument constructor is never called
System.out.println(applicationContext.getBean("test"));
System.out.println(applicationContext.getBean("test", new Object[]{"test 2"}));
}
}
output:
custom constructor called test 1
Test@1bbd23f
default constructor called
Test@1e845c2
default constructor called
Test@3c0007
So I am getting different objects for every bean instantiated as expected for scope="prototype" but somehow the third call to get bean does not use the custom constructor but the default constructor instead.
It seems like there is some caching somewhere and that causes this behavior.
Affects: 2.0.9, 2.5.1, 2.5.2, 2.5.3, 2.5.4, 2.5.5, 2.5.6, 3.0 M1, 3.0 M2, 3.0 M3