springboot无法完成变量从pom到.properties文件自动替换的问题

/ Java / 0 条评论 / 1182浏览

springboot无法完成变量从pom到.properties文件自动替换的问题

由于${}方式会被maven处理。如果你pom继承了spring-boot-starter-parent,Spring 
Boot已经将maven-resources-plugins默认的${}方式改为了@@方式,如 @name@ 。
springboot的占位符被定义为@value@了。
如果还想继续使用${}占位符方式,只需要在pom文件中加上下面配置即可.useDefaultDelimiters设置为true

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

自定义占位符
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <encoding>utf-8</encoding>
                    <useDefaultDelimiters>true</useDefaultDelimiters>
                    <delimiters>
                    	<!-- 自定义 两者都有效 -->
                        <delimiter>${*}</delimiter>
                        <!--eg:@code@-->
                        <delimiter>@</delimiter>
                        <!--<delimiter>@*@</delimiter>与上面等效-->
                    </delimiters>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

//<delimiter>@</delimiter>
Set of delimiters for expressions to filter within the resources. These delimiters are specified in the form {@code beginToken*endToken}. If no {@code *} is given, the delimiter is assumed to be the same for start and end.
springboot自定义占位符为@
在spring-boot-starter-parent.pom文件中,有:

<resource.delimiter>@</resource.delimiter>
<build>
    <pluginManagement>
        <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-resources-plugin</artifactId>
              <configuration>
                <delimiters>
                  <delimiter>${resource.delimiter}</delimiter>
                </delimiters>
                <useDefaultDelimiters>false</useDefaultDelimiters>
              </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
jscss_version
<properties>
    <maven.build.timestamp.format>yyyyMMddmm</maven.build.timestamp.format>
    <jscss_version>${maven.build.timestamp}</jscss_version>
</properties>

//默认值
<maven.build.timestamp.format>yyyy-MM-dd'T'HH🇲🇲ss'Z'</maven.build.timestamp.format>

打包加上时间
<properties>
    <maven.build.timestamp.format>yyyyMMdd</maven.build.timestamp.format>
</properties>
<build>
	<finalName> ${project.artifactId}-${project.version}_${maven.build.timestamp}</finalName>
</build>
maven的build#resource的执行顺序
<build><resources>里的多个<resource>的执行顺序:
1、filtering为false的比为true的优先执行;
2、filtering同条件的,按列表顺序执行;
3、后面执行的可以把前面执行的文件覆盖;

filtering为true时,开启替换占位符