注意
————————————————————————————————————————————
WebSecurityConfig需要添加 @EnableWebSecurity 注解
添加Security权限验证后注册中心地址需添加用户名及密码**
客户端及服务端注解
————————————————————————————————————————————
示例【转载】
简书-yanshihao
原文地址:https://www.jianshu.com/p/59eea0b6ab96
————————————————————————————————————————————
服务方配置代码
server:
port: 7001
eureka:
instance:
hostname: localhost
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
spring:
security:
user:
name: admin
password: 123456
同时服务方需要关闭Security的CSRF配置,写配置类以关闭CSRF:
@EnableWebSecurity
class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().ignoringAntMatchers("/eureka/**");
super.configure(http);
}
}
客户端
eureka:
client:
service-url:
defaultZone: http://admin:123456@localhost:7001/eureka/
————————————————————————————————————————————
Thanks
|