Eureka安全認證

Eureka 服務加入安全認證只需要在之前的服務中增加二處步驟即可:

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

其具體的依賴如下:

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
    </dependencies>
</project>
  • 修改配置文件
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客戶端的配置,

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的安全認證官網鏈接

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容