Maven Springboot项目配置文件相互读取
pom文件和properties/yml配置文件互相读取
pom文件读取资源文件(properties/yml)
pom配置
<!-- 读取properties文件 -->
<plugin>
<!-- <groupId>org.codehaus.mojo</groupId> -->
<!-- <artifactId>properties-maven-plugin</artifactId> -->
<!-- <version>1.0-alpha-2</version> -->
<groupId>it.ozimov</groupId>
<artifactId>yaml-properties-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>src/main/resources/application.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
读取
直接${变量名}
读取
资源文件(properties/yml)读取pom文件
pom配置
<properties>
<java.version>1.8</java.version>
<profileActive>${spring.profiles.active}</profileActive>
</properties>
<resources>
<resource>
<directory>src/main/resources</directory>
<!-- 指定为true是,属性文件的占位符解析表达式就可以读取pom属性了 -->
<filtering>true</filtering>
<includes>
<!-- 这里只能读取到pom本身的变量,从properties读取的值这里取不到 -->
<!-- <include>config/application-${profileActive}.properties</include> -->
<include>application.properties</include>
<include>config.properties</include>
<include>log4j2.xml</include>
<include>init.yml</include>
</includes>
</resource>
</resources>
读取
spring.profiles.active=@profileActive@