赞
踩
<!-- 引入spring的security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
spring:
security:
user:
name: admin
password: a
此时 其他服务也无法在eureka上注册了,所以要在其他服务端中加入登录配置
解决方案; 在 其他服务端的application.yml中修改登录eureka登录配置
eureka:
client: # 客户端进行Eureka注册的配置
service-url:
#defaultZone: http://localhost:7001/eureka
defaultZone: http://admin:a@localhost:7001/eureka #授信用户登录
并且要求在eureka模块中增加一个类: 关闭 csrf
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
@EnableWebSecurity
public class EurekaSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http)throws Exception{
http.csrf().disable();
super.configure(http);
}
}
关于什么是csrf 可以查看 :https://www.cnblogs.com/hyddd/archive/2009/04/09/1432744.html
之后
再重启eureka,再重启 服务端,可以看到 服务端在eureka中注册成功
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。