小编典典

Maven资源过滤不起作用-由于Spring Boot的依赖性

spring-boot

这个问题已经在这里有了答案

使用Spring Boot进行Maven资源过滤:无法解析占位符 (1个答案)

3年前关闭。

在一个Maven项目中,我尝试使用Maven资源过滤替换一些令牌,但是它不起作用。我还有其他一些可行的项目,但无法在此单个项目中运行,不确定有什么问题。

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

我尝试了如下不同的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

    <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来解决此问题。


阅读 313

收藏
2020-05-30

共1个答案

小编典典

最后在我的评论中找到链接的答案。由于这是一个Spring Boot应用程序…特殊情况…这些符号应为

@xxxxx@  instead of ${xxxxx}

所以我的财产文件如下

### Spring boot properties
jdbc.url=@jdbc.url@
ldap.domain=@ldap_domain@
ldap.url=@ldap_url@
2020-05-30