qq_风逝叶落_0
2019-04-12 22:33
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();
}
直接打印两个对象的地址值,看看相不相同。每次getBean都相当于new一次
Spring入门篇
268787 学习 · 963 问题
相似问题