在test下直接执行main方法会导致找不到资源文件,发现是Test output path下的目录没有资源文件,导致加载不到。
在pom.xml中配置增加以下配置后执行test目录下的main方法成功
<build>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
<testResource>
<directory>${project.basedir}/src/main/resources</directory>
</testResource>
</testResources>
</build>