(1)导入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
(2)设置账号密码
spring.security.user.name=root
spring.security.user.password=root
(3)在服务端增加配置类
关闭防止跨域攻击,如需跨域。
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter{
@Override
protected void configure(HttpSecurity http) throws Exception {
// TODO Auto-generated method stub
http.csrf().disable();
super.configure(http);
}
}
(4)provider添加账号密码
eureka:
client:
service-url:
defaultZone: http://root:root@euk1.com:7001/eureka/