【问题标题】:spring-boot-maven-plugin not filteringspring-boot-maven-plugin 没有过滤
【发布时间】:2019-08-29 15:33:59
【问题描述】:

这是我在一个简单项目中的 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.7.RELEASE</version>
        <relativePath/>
    </parent>
    <groupId>com.example</groupId>
    <artifactId>test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>test</name>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

    <build>
        <filters>
            <filter>src/main/resources/filters/test.filter</filter>
        </filters>
        <resources>
            <resource>
                <directory>src/main/resources/export</directory>
                <filtering>true</filtering>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

这是我的资源

src/main/resources/export/app.properties

Hello ${test_prop}

src/main/resources/filters/test.filter

test_prop = World

当我运行 mvn resources:resourcesmvn clean package 时,目标文件夹中的结果是原始 app.properties(无过滤)。有谁知道它为什么不过滤?

【问题讨论】:

    标签: filtering spring-boot-maven-plugin


    【解决方案1】:

    来自 Spring 文档:如果您使用 spring-boot-starter-parent,则可以使用 @..@ 占位符引用您的 Maven '项目属性',如下例所示:

    app.encoding=@project.build.sourceEncoding@
    app.java.version=@java.version@
    

    https://docs.spring.io/spring-boot/docs/current/reference/html/howto-properties-and-configuration.html

    【讨论】:

      猜你喜欢
      • 2022-01-16
      • 2020-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-06
      • 2017-06-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多