Eureka安全认证

Eureka 服务加入安全认证只需要在之前的服务中增加二处步骤即可:

  • 在Eureka Server中加入spring-boot-starter-security依赖

其具体的依赖如下:

    
        
            org.springframework.cloud
            spring-cloud-starter-eureka-server
        
        
            org.springframework.boot
            spring-boot-starter-security
        
    

  • 修改配置文件
security:
  basic:
    enabled: true
  user:
    name: miaozhihao
    password: 123456
server:
  port: 8761
eureka:
  instance:
    hostname: localhost
  client:
    register-with-eureka: false
    fetch-registry: false
    service-url:
     defaultZone: http://miaozhihao:123456@${eureka.instance.hostname}:${server.port}/eureka/

启动Eureka服务:


Eureka安全认证_第1张图片

输入配置文件中配置的用户名和密码即可。

附上一份Eureka客户端的配置,

spring:
  application:
    name: order-service
eureka:
  client:
    service-url:
     defaultZone: http://miaozhihao:123456@localhost:8761/eureka
  instance:
    instance-id:  ${spring.application.name}:${spring.cloud.client.ipAddress}:${spring.application.instance_id:${server.port}}
server:
  port: 9090
user:
  service:
    url: http://user-service

就改变一处eureka.client.

Eureka Server的安全认证官网链接

你可能感兴趣的:(Eureka安全认证)