从零搭建一个SpringCloud项目之Config(五)
2021-02-15 04:18
标签:测试 rod tps class oracl 修改 dem 新建 request 注意:git上的配置yml文件名要对应这里配置的spring.application.name 到此最简单的配置中心搭建完成!!! 整合bus的方案 服务端修改: 客户端: 在读取配置的类上加@RefreshScope注解 https://www.oracle.com/java/technologies/javase-jce8-downloads.html http://localhost:9100/encrypt/status 返回OK代表配置成功 http://localhost:9100/decrypt 密文内容前需要写{cipher},并且用单引号括起来 避免直接访问配置文件 git地址:https://github.com/mmcLine/spring-cloud-study 从零搭建一个SpringCloud项目之Config(五) 标签:测试 rod tps class oracl 修改 dem 新建 request 原文地址:https://www.cnblogs.com/javammc/p/12716691.html配置中心
一、配置中心服务端
server:
port: 9100
spring:
application:
name: study-config-server
cloud:
config:
server:
git:
uri: https://github.com/mmcLine/cloudconfigTest.git
username: mmcLine
password: ********
@SpringBootApplication
@EnableConfigServer
public class StudyConfigApplication {
public static void main(String[] args) {
SpringApplication.run(StudyConfigApplication.class);
}
}
spring:
profiles:
active: test
---
spring:
profiles: test
application:
name: config-test
server:
port:9101
---
spring:
profiles: prod
application:
name: config-prod
server:
port:9102
例:http://localhost:9100/application-test.yml
例:http://localhost:9100/application/test/master
例:http://localhost:9100/master/application-test.yml二、配置中心客户端
spring:
application:
name: study-trade
cloud:
config:
uri: http://localhost:9100
profile: test
label: master
@RestController
public class ConfigTestController {
@Value("${ordernotiry}")
private Boolean ordernotiry;
@RequestMapping("/testconfig")
public String testconfig(){
return String.valueOf(ordernotiry);
}
}
三、升级不重启修改配置文件
spring:
cloud:
bus:
enabled: true
trace:
enabled: true
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
management:
endpoints:
web:
exposure:
include: "bus-refresh"
@RestController
@RefreshScope
public class ConfigTestController {
@Value("${ordernotiry}")
private Boolean ordernotiry;
@RequestMapping("/testconfig")
public String testconfig(){
return String.valueOf(ordernotiry);
}
}
四、配置加密
encrypt:
key: trademmc
5. 测试加密方法
loginpass: ‘{cipher}941c15446567e8211931cf0d25f81696871f5a5ea74fac46638eed71db24e76b‘
spring:
security:
user:
name: root
password: 123456
basic:
enable: true
spring:
cloud:
config:
uri: http://localhost:9100
profile: test
label: master
username: root
password: 123456
文章标题:从零搭建一个SpringCloud项目之Config(五)
文章链接:http://soscw.com/index.php/essay/55487.html