前四章源码怎么运行
前四章源码 是什么工程啊 连pom文件都没有 怎么启这个项目
前四章源码 是什么工程啊 连pom文件都没有 怎么启这个项目
2018-12-12
pom只是在管理项目,不做启动工作,pom里面管理是引入的jar包、版本以及各个模块之间的依赖。前四章只是在用Junit测试的,给你个源码吧
public class UnitTestBase {
private ClassPathXmlApplicationContext context;
private String springXMLPath;
public UnitTestBase() {
}
public UnitTestBase(String springXMLPath) {
this.springXMLPath = springXMLPath;
}
@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();
}
}
@After
public void after() {
context.destroy();
}
@SuppressWarnings("unchecked")
protected <T extends Object> T getBean(String beanId) {
return (T) context.getBean(beanId);
}
protected <T extends Object> T getBean(Class<T> clazz) {
return context.getBean(clazz);
}
}上面这个是Junit测试类的父类,你写的测试类集成它就行了
举报