本文共 2527 字,大约阅读时间需要 8 分钟。
pom.xml 增加 security 安全认证
org.springframework.cloud spring-cloud-config-server org.springframework.boot spring-boot-starter-security
application.yml 配置配置中心的帐号密码
security: basic: enabled: true user: name: user password: password123server: port: 8080
pom.xml 增加对config client 的依赖
org.springframework.cloud spring-cloud-starter-config org.springframework.boot spring-boot-starter-web
bootstrap.yml 配置 config server的地址 username: config server 的用户名 password: config server 的password
spring: cloud: config: uri: http://localhost:8080 # curl style username: user password: password123 profile: dev label: master # 当configserver的后端存储是Git时,默认就是master application: name: foobar
pom.xml 增加对eureka client 的依赖
org.springframework.cloud spring-cloud-config-server org.springframework.cloud spring-cloud-starter-eureka
application.yml
server: port: 8080spring: application: name: microservice-config-server-eurekaeureka: client: serviceUrl: defaultZone: http://user:password123@localhost:8761/eureka instance: prefer-ip-address: true
应用入口
@SpringBootApplication@EnableConfigServer@EnableDiscoveryClientpublic class ConfigServerApplication { public static void main(String[] args) { SpringApplication.run(ConfigServerApplication.class, args); }}
pom.xml 增加eureka clent的依赖和 端点的依赖
org.springframework.cloud spring-cloud-starter-eureka org.springframework.boot spring-boot-starter-actuator
bootstrap.yml 配置eureka 服务器的地址
eureka: client: serviceUrl: defaultZone: http://user:password123@localhost:8761/eureka instance: prefer-ip-address: true
应用入口类
@SpringBootApplication@EnableDiscoveryClientpublic class ConfigServerApplication { public static void main(String[] args) { SpringApplication.run(ConfigServerApplication.class, args); }}
转载地址:http://paonn.baihongyu.com/