首页 > 解决方案 > 他们是否有任何替代方法可以将资源过滤与 Maven 一起用于 Spring Boot 应用程序?

问题描述

我正在开发一个使用 Maven 作为构建工具的 Spring Boot 应用程序,我试图在其中使用 Maven 的资源过滤。它似乎不起作用,因为它适用于其他春季项目。我怎样才能实现它?

我在 pom.xml 中使用 spring-boot-starter 作为父级。我在 src/main/resource 文件夹中有 myconfig.properties 文件。我在 myconfig.properties 文件中有如下属性之一:

prop.first=@project.version@

这里 @ 是 spring-boot 默认令牌过滤器,应该使用它来代替 $。

<project>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.1.RELEASE</version>
        <relativePath/>
     </parent>

    <version>19.6.0</version>
    ......
    <build>
        .....
        <resource>
            <directory>/src/main/resources</directory>
            <filtering>true</filtering>
            <includes>
                <include>**/myconfig.properties</include>
            </includes>                
        </resource>
        .....
    </build>
    .....
</project>

由于我的“project.version”是 19.6.0,所以在使用 maven 构建时,我期望 myconfig.properties 文件中的 prop.first 为:

prop.first=19.6.0

但实际上,该属性永远不会被替换,并且在文件中仍然与以下内容相同:

prop.first=@project.version@

我在文档中的某处读到了 Maven 过滤不适用于 Spring Boot 中的 src/main/resources 。虽然与 maven 相同的过滤适用于 spring-boot 以外的其他类型的项目,但在我的情况下,进行资源过滤的替代方法是什么?

标签: springmavenspring-boot

解决方案


推荐阅读