maven测试

来源:互联网 发布:2017网络红歌排行榜 编辑:程序博客网 时间:2024/05/29 03:29


今天在维护以前做的项目的时候,使用maven的install命令,进行test的时候,都会报错,说是找不到applicationContext.xml文件

原因是他把测试文件放在java目录下了(如图所示),但不是 maven约定的资源文件目录,src/main/resources 是资源目录,  src/test/resources 是测试资源目录。所以需要建该目录,将资源文件放在该文件里就好了。建好后,maven update一下,识别你建的resources目录。



加载spring资源的代码:

public abstract class AbsTest {protected ClassPathXmlApplicationContext context;@Beforepublic void init() {context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");}@Afterpublic void dispose() {if (context != null) {context.close();}}}

ps:

maven有自己的配置文件(pom.xml) eclipse有自己的配置文件 .classpath .project .settings
maven2eclipse插件可以把 maven配置转化成eclipse配置, 这样在eclipse中就可以识别maven中的那些 源代码目录之类的了。 新版本的eclipse自带这个插件。



0 0