一、config-server
1、pom配置
<!--boot版本和cloud版本-->
<spring.boot.version>2.1.5.RELEASE</spring.boot.version>
<spring.cloud.version>Greenwich.SR2</spring.cloud.version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<!-- springcloud-bus依赖实现配置自动更新,rabbitmq -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
</dependencies>
2、bootstrap.yml配置
server:
port: 8383
spring:
application:
name: config-server
cloud:
config:
server:
git:
uri: https://github.com/bell-zhouxiaobing/spring-cloud/
search-paths:
- config-repo
username:
password:
bus:
trace:
enabled: true
rabbitmq:
host: ip
port: 5672
username: username
password: password
management:
endpoints:
web:
exposure:
include:
- "*"
# 加密config配置文件,加密后的字符串前缀{cipher}
encrypt:
# key: staginfo-config-key # 对称加密密钥
key-store:
alias: mytest
password: mypass # 设置store的密码
location: classpath:mytest.jks
secret: mypass # mytest密码
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
3、启动类配置
@SpringBootApplication
@EnableConfigServer
@EnableDiscoveryClient
public class StaginfoCloudConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(StaginfoCloudConfigServerApplication.class, args);
}
}
二、config-client
1、pom配置
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!-- config 依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- config 依赖end -->
</dependencies>
2、bootstrap.yml配置
server:
port: 8182
spring:
application:
name: user-consumer
cloud:
config:
discovery:
enabled: true
service-id: config-server
# 开发环境
profile: dev
# 版本分支
label: master
rabbitmq:
host: ip
port: 5672
username: username
password: password
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
3、启动类配置
@SpringBootApplication
@EnableDiscoveryClient
@RestController
@RefreshScope
public class StaginfoCloudConfigClientApplication {
public static void main(String[] args) {
SpringApplication.run(StaginfoCloudConfigClientApplication.class, args);
}
@Value("${test}")
private String test;
@GetMapping("/hi")
public String hi() {
return test;
}
}