博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring Cloud 配置中心 认证和高可用
阅读量:3727 次
发布时间:2019-05-22

本文共 2527 字,大约阅读时间需要 8 分钟。

Spring Cloud 配置中心 认证和高可用

更多干货

  • 配置中心认证
  • 配置中心高可用

一、配置中心认证

config server

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

config client 客户端

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

二、配置中心与eureka结合

config server 配置中心服务端

pom.xml 增加对eureka client 的依赖

org.springframework.cloud
spring-cloud-config-server
org.springframework.cloud
spring-cloud-starter-eureka

application.yml

  • spring.application.name 配置应用名称
  • eureka.client.serviceUrl.defaultZone 配置eureka 服务器地址
server:  port: 8080spring:  application:    name: microservice-config-server-eurekaeureka:  client:    serviceUrl:      defaultZone: http://user:password123@localhost:8761/eureka  instance:    prefer-ip-address: true

应用入口

  • @EnableDiscoveryClient 激活eureka客户端
@SpringBootApplication@EnableConfigServer@EnableDiscoveryClientpublic class ConfigServerApplication {  public static void main(String[] args) {    SpringApplication.run(ConfigServerApplication.class, args);  }}

config client 配置中心客户端

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

应用入口类

  • @EnableDiscoveryClient 激活 Eureka客户端
@SpringBootApplication@EnableDiscoveryClientpublic class ConfigServerApplication {  public static void main(String[] args) {    SpringApplication.run(ConfigServerApplication.class, args);  }}

转载地址:http://paonn.baihongyu.com/

你可能感兴趣的文章
爬虫selenium框架爬取携程酒店数据
查看>>
Exception in thread “main“ java.lang.ArrayIndexOutOfBoundsException: 4
查看>>
逆序输出一个数字Python
查看>>
安装虚拟机及Linux系统常见问题解决 虚拟机黑屏 主机重启
查看>>
批改网不能粘贴使用selenium输入作文正文
查看>>
2021-05-27 爬虫数据输出\uXXXX如何转化中文
查看>>
Linux Ubuntu系统完整安装MySQL步骤及配置远程主机连接
查看>>
java后端学习小组近段时间学习感悟
查看>>
LeedCode刷题感悟
查看>>
LeedCode刷题经验之寻址对称子序列:
查看>>
16周个人总结
查看>>
Android Studio下载
查看>>
埃拉托列尼塞算法(求质数)
查看>>
欧几里得算法(原始形式减法)证明
查看>>
扩展欧几里得算法
查看>>
XML Schema 简易入门教程
查看>>
Java反射机制学习笔记(1)
查看>>
关于浏览器下载文件名乱码问题
查看>>
双子针算法总结
查看>>
二叉树的非递归前序,中序,后序遍历实现(java,全部用栈)
查看>>