springboot application无法使用$获取pom变量问题

时间:2025-04-21 09:35:26

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

= ${}

但是${}无法从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>


或者使用

<configuration>
                    <delimiters>
                        <delimiter>@</delimiter>
                    </delimiters>
                    <useDefaultDelimiters>false</useDefaultDelimiters>
                </configuration>


将<useDefaultDelimiters>false</useDefaultDelimiters>
改为<useDefaultDelimiters>true</useDefaultDelimiters>