Spring 在另一个项目中重用资源和上下文
我有一个项目如下:Spring 在另一个项目中重用资源和上下文,spring,junit,spring-test,spring-test-mvc,Spring,Junit,Spring Test,Spring Test Mvc,我有一个项目如下: Project Project-A/ src/test/java/ someTests.java src/test/resources database/ create.sql insert.sql spring/ test-config.xml project-
Project
Project-A/
src/test/java/
someTests.java
src/test/resources
database/
create.sql
insert.sql
spring/
test-config.xml
project-B/
src/test/java
otherTests.java
项目B的pom.xml:
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>Project-A</artifactId>
</dependency>
我想在otherTests.java中重用test-config.xml、create.sql和insert.sql
我已经在otherTests.java中尝试过了
@ContextConfiguration(locations = {"classpath*:spring/test-dao-config.xml"})
但这似乎不起作用
编辑:在Geoand的回答帮助中,我不再有与bean相关的异常,但现在我有了一个
FileNotFoundException:类路径资源
无法打开[exception messages.properties],因为它没有打开
存在
因为我不清楚到底做了哪些更改,我不知道如何修复此问题。。。
异常消息在webapp-config.xml中被用作
我认为问题在于,尽管您正在将Project-A导入Project-B,但Maven并未包含测试代码。查看有问题的解决方案,看看是否有帮助
编辑:
一旦让maven也导入测试代码,就需要在/test/resources下创建.properties文件,其中包含应用程序中使用的属性的测试值
@ContextConfiguration(locations = {"classpath*:spring/test-dao-config.xml"})