目录
一、使用场景
由于分布式架构,系统中有很多微服务应用,为了方便打包、统一服务配置,下面介绍通过
parent pom
(属性值会被继承)中的properties
标签将属性值传递到properties或yml配置文件(包括bootstrap.properties文件)。
二、 使用方法
2.1 在parent pom
文件中增加(使用maven渲染properties或yml)
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
2.2 在parent pom
中的properties
标签加入属性值
<properties>
<!--配置中心地址-->
<spring.cloud.config.uri>http://192.168.2.118:8080</spring.cloud.config.uri>
<!--指定配置文件-->
<spring.profiles.active>test</spring.profiles.active>
<!--日志文件目录-->
<lettin.log.home>/lettin/lettin-pro/logs</lettin.log.home>
<!--控制台日志等级-->
<lettin.log.console.level>off</lettin.log.console.level>
<!--指定远程 docker api地址,你的docker安装的地址-->
<dockerHost>https://192.168.2.118:2075</dockerHost>
<!--docker仓库地址-->
<docker.repostory>192.168.2.118:5000/lettin/server</docker.repostory>
</properties>
2.3 properties
配置文件中获取属性
# 配置中心
spring.cloud.config.uri=@spring.cloud.config.uri@
# 配置文件类型
spring.cloud.config.profile=@spring.profiles.active@
# 日志文件目录
lettin.log.home=@lettin.log.home@
# 控制台日志等级
lettin.log.console.level=@lettin.log.console.level@
# jta日志目录
spring.jta.log-dir=@lettin.log.home@/jta