我正在尝试向Spring
应用程序上下文文件添加一些过滤,该文件位于src/main/resources
文件夹中,但它不起作用。我将我的过滤器文件放在src/main/filters
我尝试了很多解决方案,但是当我通过maven install或junit启动单元测试时没有任何解决方案,但如果我跳过测试它正在过滤它正在工作。
我修改了文件.classPath
,我从文件中删除了exclude
属性
edit classpath solution然后我读了这篇文章bug in maven-resources-plug ,他说maven-resources-plugin中有一个错误,所以我将插件更新到了更新的版本,但它仍然没有用。
我的pom.xml:
<build>
<finalName>core-impl</finalName>
<directory>target</directory>
<sourceDirectory>src/main/java</sourceDirectory>
<outputDirectory>target/classes</outputDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<testOutputDirectory>target/test-classes</testOutputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<filters>
<filter>src/main/filters/filter.properties</filter>
</filters>
</build>
答案 0 :(得分:2)
我试过这个解决方案而且它正在运行。
<execution>
<id>default-resources</id>
<phase>process-resources</phase>
<goals>
<goal>resources</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<filters>
<filter>${basedir}/src/main/filters/filter.properties</filter>
</filters>
</configuration>
</execution>
<execution>
<id>default-testResources</id>
<phase>process-test-resources</phase>
<goals>
<goal>resources</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<filters>
<filter>${basedir}/src/test/filters/filter.properties</filter>
</filters>
</configuration>
</execution>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<testResources>
<testResource>
<filtering>true</filtering>
<directory>src/test/resources</directory>
</testResource>
</testResources>