美文网首页
Maven install,占位符${}没有被替换

Maven install,占位符${}没有被替换

作者: 雨夏_ | 来源:发表于2020-04-29 17:29 被阅读0次

问题:

maven多module开发过程中,父module继承了

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

现在想实现配置文件的多环境运行,比如有application-sit.yml,application-uat.yml,想在application.yml文件中通过变量env控制不同的环境使用不同的配置文件,
但是打包的时候发现怎么都替换不了,打包的命令:mvn clean package -DskipTests=true -Denv=uat 或者mvn clean package -DskipTests=true -Denv=sit,
最后打完包application.yml还是如下

spring:
  profiles:
    active: ${env}

解决办法:
添加useDefaultDelimiters标签,并且设置为true

<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <configuration>
        <encoding>utf-8</encoding>
        <useDefaultDelimiters>true</useDefaultDelimiters>
    </configuration>
</plugin>

原因:
spring-boot为了保护application.yml和application.properties,修改了默认的占位符${...}为@...@,受影响的应该是spring boot 1.3.0以上的版本,
加上那句表示使用默认的占位符

Maven自定义占位符:

<plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-resources-plugin</artifactId>
          <version>2.5</version>
          <configuration>
              <useDefaultDelimiters>false</useDefaultDelimiters>
              <delimiters>
                  <delimiter>$[*]</delimiter>
              </delimiters>
              <encoding>UTF-8</encoding>
          </configuration>
</plugin>

转载:maven占位符$变量无法替换

相关文章

网友评论

      本文标题:Maven install,占位符${}没有被替换

      本文链接:https://www.haomeiwen.com/subject/fnenwhtx.html