package com.bjpowernode.test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.bjpowernode.spring.Bean1;
import com.bjpowernode.spring.Bean2;
import com.bjpowernode.spring.Bean6;
import junit.framework.TestCase;
public class InjectionTest extends TestCase {
private BeanFactory factory;
/**
* TestCase的初始化方法
*/
@Override
protected void setUp() throws Exception {
// String[] configLocations = new String[]{"applicationContext.xml",
// "applicationContext-editor.xml"};
// factory = new ClassPathXmlApplicationContext(configLocations);
factory = new ClassPathXmlApplicationContext("applicationContext-*.xml");
}
/**
* TestCase的销毁方法
*/
@Override
protected void tearDown() throws Exception {
}
public void testScope() {
Bean6 bean6 = (Bean6) factory.getBean("bean6");
Bean6 bean62 = (Bean6) factory.getBean("bean6");
System.out.println(bean6 == bean62);
}
}
3.spring bean的作用域(是否单例):测试
最新推荐文章于 2023-02-04 15:11:19 发布