一、前提
- 报错的xml文件定义在src/test/resource中
- 报错:Caused by: java.io.FileNotFoundException: class path resource [initForTest.xml] cannot be opened because it does not exist
- java代码:
@ContextConfiguration({
"classpath:initForTest.xml"
})
public class ZTest extends AbstractJUnit4SpringContextTests {
二、解决办法
修改classpath配置,默认可能会有文件的过滤,需要取消文件过滤。
- 修改前的相关配置:
<classpathentry excluding="**" kind="src" output="target/classes" path="src/test/resource"/>
- 修改后的相关配置:
<classpathentry kind="src" output="target/classes" path="src/test/resource"/>