▶ Spring Boot 依赖与配置
Maven 依赖
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Greenwich.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
.....
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-config</artifactId>
</dependency>
</dependencies>
▶ 使用说明
1、部署 Consul
- 参考文档:上一篇
2、在 resources 路径下添加配置文件 bootstrap.properties,示例如下:
# consul 基本配置
spring.cloud.consul.host=127.0.0.1
spring.cloud.consul.port=8500
# 启用 consul 配置中心
spring.cloud.consul.config.enabled=true
# 基础文件夹,默认值 config
spring.cloud.consul.config.prefix=config
# 应用文件夹,默认值 application,consul 会加载 config/<applicationName> 和 config/<defaultContext> 两份配置,设置为相同值,则只加载一份
spring.cloud.consul.config.default-context=testApp
spring.application.name=testApp
# 环境分隔符,默认值 ","
spring.cloud.consul.config.profile-separator=-
# 配置转码方式,默认 key-value&