Maven 资源过滤不起作用 - 由于 Spring Boot 依赖 [英] Maven resource filtering not working - because of spring boot dependency

查看:49
本文介绍了Maven 资源过滤不起作用 - 由于 Spring Boot 依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个 Maven 项目中,我尝试使用 Maven 资源过滤替换一些令牌,但它不起作用.我还有一些其他项目可以工作,但在这个项目中不起作用,不确定是什么问题.

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.

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

The property files is in location /src/main/resources/my.properties

我尝试了如下不同的 maven 命令,但不起作用.

I tried different maven commands as below but does not work.

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

    <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>

更新:-

我发现这个问题是由 spring boot 依赖引起的.如果我评论 <parent> 部分和其他 spring boot 依赖项,那么它可以正常工作并且能够替换令牌.但仍然不确定如何通过保持 spring boot 来解决这个问题.

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 应用程序……特殊情况……符号应该是

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}

所以我的属性文件如下

### Spring boot properties
jdbc.url=@jdbc.url@
ldap.domain=@ldap_domain@
ldap.url=@ldap_url@

这篇关于Maven 资源过滤不起作用 - 由于 Spring Boot 依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆