在pom.xml里编写
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<profiles>
<profile>
<id>test</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<filters>
<filter>./profiles/score-test.properties</filter>
</filters>
</build>
</profile>
<profile>
<id>uat</id>
<build>
<filters>
<filter>./profiles/score-uat.properties</filter>
</filters>
</build>
</profile>
</profiles>
</project>
src/main/resources/application.properties
server.port=@server.port@
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=@spring.datasource.url@
spring.datasource.username=@spring.datasource.username@
spring.datasource.password=@spring.datasource.password@
mybatis.configuration.map-underscore-to-camel-case=true
mybatis.configuration.jdbc-type-for-null=NULL
logging.config=classpath:logback.xml
spring.main.allow-bean-definition-overriding=true
在score-test.properties和score-uat.properties中根据环境的不同添加具体的参数,比如数据库地址和端口等等。
package后在target/classes/application.properties中可以看到选择了哪个properties就会显示哪个properties里参数的值