Java Maven 资源过滤不起作用 - 由于 Spring Boot 依赖
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36501017/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven resource filtering not working - because of spring boot dependency
提问by Jay
In a maven project I trying to replace some tokens using maven resource filtering but it does not work. I have some other projects which works but does not work in this single project not sure what is wrong.
在 Maven 项目中,我尝试使用 Maven 资源过滤替换一些令牌,但它不起作用。我还有一些其他项目可以工作,但在这个项目中不起作用,不知道出了什么问题。
The property files is in location /src/main/resources/my.properties
属性文件位于 /src/main/resources/my.properties
I tried different maven commands as below but does not work.
我尝试了如下不同的 maven 命令,但不起作用。
mvn clean install
mvn clean install resources:resources
my.properties
我的财产
### Spring boot properties
jdbc.url=${jdbc.url}
ldap.domain=${ldap_domain}
ldap.url=${ldap_url}
pom.xml
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jai</groupId>
<artifactId>client</artifactId>
<version>0.0.6-SNAPSHOT</version>
<name>client</name>
<description>client web application</description>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.2.RELEASE</version>
<relativePath />
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>
</dependency>
</dependencies>
<build>
<finalName>client</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>exec-bower-install</id>
<phase>generate-sources</phase>
<configuration>
<executable>bower</executable>
<arguments>
<argument>install</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<!-- localhost environment -->
<profile>
<id>local</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<ldap_domain>mydomain.local</ldap_domain>
<ldap_url>ldap://server:389</ldap_url>
<jdbc.url>testttttttttttttttttttttt</jdbc.url>
</properties>
</profile>
</profiles>
</project>
Update:-
更新:-
I figured out this problem is caused due to the spring boot dependency.
If I comment the <parent>
section and other spring boot dependencies, then it works fine and able to replace the token. But still not sure how to fix this by keeping spring boot.
我发现这个问题是由于 spring boot 依赖引起的。如果我评论该<parent>
部分和其他 Spring Boot 依赖项,则它可以正常工作并且能够替换令牌。但仍然不确定如何通过保持弹簧靴来解决这个问题。
采纳答案by Jay
At last found the answer from the link in my comments. As this is a spring boot application ...special case... the notations should be
最后从我评论中的链接中找到了答案。由于这是一个弹簧启动应用程序......特殊情况......符号应该是
@xxxxx@ instead of ${xxxxx}
So my property file would be as below
所以我的财产文件如下
### Spring boot properties
[email protected]@
ldap.domain=@ldap_domain@
ldap.url=@ldap_url@