springboot读取pom配置

我在maven的pom文件中进行了多环境变量配置,引用了maven-resources-plugin,在application.properties文件中通过以下配置指定不同环境下的配置文件,

spring.profiles.active = ${profiles.active}

但是${profiles.active}无法从pom文件中获取变量值替换。这个问题困扰了很久,终于在原博主的文章中发现了问题的根源。

引用原博主的一句话:

由于${}方式会被maven处理。如果你pom继承了spring-boot-starter-parent,Spring
Boot已经将maven-resources-plugins默认的${}方式改为了@@方式,如@name@

如果还想继续使用${}占位符方式,只需要在pom文件中加上下面配置即可:

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <encoding>utf-8</encoding>
                    <useDefaultDelimiters>true</useDefaultDelimiters>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
  
  
发布了18 篇原创文章 · 获赞 5 · 访问量 6723

猜你喜欢

转载自blog.csdn.net/qq_28687183/article/details/90199910
今日推荐