初始化和销毁是在IOC容器的启动和销毁过程中执行的,那和这个基类有什么关系?
初始化和销毁的方法是通过xml指定的,具体的方法在bean中。
按我的理解,启动,在加载xml后执行初始化方法,在关闭容器后执行销毁方法
那么这里讲这个基类又是做什么?
为什么要强调下基类的在before和after中的
context.start();
context.destroy();
这里是这两个在调用?
看了下代码,在这个继承的基类中重写了before方法和after方法
其中的before
@Before
public void before() {
if (StringUtils.isEmpty(springXmlpath)) {
springXmlpath = "classpath*:spring-*.xml";
}
try {
context = new ClassPathXmlApplicationContext(springXmlpath.split("[,\\s]+"));
context.start();
} catch (BeansException e) {
e.printStackTrace();
}
}context.start();看起来是启动容器,也就是说在执行这个test方法前,要先通过before启动容器(我一直以为直接super.getBean就好了)