項目目錄
Maven多環(huán)境配置
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<profiles.active>dev</profiles.active>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<profiles.active>test</profiles.active>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<profiles.active>prod</profiles.active>
</properties>
</profile>
</profiles>
Maven Filters
配置
基礎(chǔ)屬性配置, 配置后響應(yīng)的文件中的字段會轉(zhuǎn)化為 Maven Properties
<!-- java properties 轉(zhuǎn)化為 maven properties -->
<filters>
<filter>src/main/resources/conf/${profiles.active}/test.properties</filter>
<filter>src/main/resources/conf/${profiles.active}/test2.properties</filter>
</filters>
根據(jù)項目實際情況配置
Maven Resources
配置
** 開啟 filtering
默認(rèn)為 false
<resources>
<resource>
<directory>src/main/resources</directory>
<!-- 開啟 filter -->
<filtering>true</filtering>
</resource>
</resources>
application.yaml(.properties)
配置
server:
port: 9001
servlet:
context-path: /with-maven
spring:
profiles:
active: @profiles.active@
# admin properties
sys:
admin:
id: ${admin.id} # 可以使用${}但是需要注意引入的字段名不能跟yaml(properties)中沖突
name: @admin.name@ # 標(biāo)準(zhǔn)的引用maven properties屬性引用
age: @admin.age@
address: @admin.address@