慕码人7551565
2020-11-27 16:51
class UnitTestBase 这个类就不能说一下吗? 完整的代码在哪里
package com.imooc.test.base;
import org.junit.After;
import org.junit.Before;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class UnitTestBase {
String springXmlPath;
ClassPathXmlApplicationContext context;
public UnitTestBase() {}
public UnitTestBase(String springXmlPath){
this.springXmlPath = springXmlPath;
}
@Before
public void before(){
if("" == springXmlPath){
springXmlPath = "classpath*:spring-*.xml";
}
try{
context = new ClassPathXmlApplicationContext(springXmlPath.split("[,\\s]+"));
context.start();
}catch(Exception e){
e.printStackTrace();
}
}
@After
public void after(){
context.destroy();
}
public <T extends Object > T getBean(String beanId){
try{
return (T) context.getBean(beanId);
}catch(Exception e){
e.printStackTrace();
return null;
}
}
}
Spring入门篇
268784 学习 · 963 问题
相似问题