為什么我設(shè)置了prototype 測試的結(jié)果還是singleton?
Java代碼:
ApplicationContext context;
public OneInterfaceImplTest() {
context = new ClassPathXmlApplicationContext("spring-ioc.xml");
}
@Test
public void test() {
OneInterface oneInterface1 = (OneInterface) context.getBean("oneInterface");
System.out.println(oneInterface1.hello2("123"));
// ApplicationContext context1 = new ClassPathXmlApplicationContext("spring-ioc2.xml");
OneInterface oneInterface2 = (OneInterface) context.getBean("oneInterface");
System.out.println(oneInterface2.hello2("123"));
}
配置項:<bean class="daoImpl.InjectionDAOImpl" id="InjectionDAO" scope="prototype"></bean>
impl方法:
@Override
public String hello2(String string) {
// TODO Auto-generated method stub
return "" +? this.hashCode();
}
2019-04-13
直接打印兩個對象的地址值,看看相不相同。每次getBean都相當(dāng)于new一次