Maven 资源过滤不起作用-因为弹簧启动依赖

在一个 maven 项目中,我试图使用 maven 资源过滤来替换一些令牌,但是没有用。我有一些其他的项目,工程,但不工作,在这个单一的项目不确定什么是错误的。

属性文件位于位置/src/main/resources/my.properties

我尝试了以下不同的 maven 命令,但是不起作用。

mvn clean install
mvn clean install resources:resources

我的财产

### Spring boot properties
jdbc.url=${jdbc.url}
ldap.domain=${ldap_domain}
ldap.url=${ldap_url}

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>

更新: -

我发现这个问题是由于弹簧引导依赖性造成的。 如果我注释 <parent>部分和其他弹簧引导依赖项,那么它工作得很好,能够替换令牌。但仍然不知道如何解决这一问题,保持弹簧启动。

39114 次浏览

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
jdbc.url=@jdbc.url@
ldap.domain=@ldap_domain@
ldap.url=@ldap_url@