1、Spring boot 版本
<version>2.2.5.RELEASE</version>
2、Eureka POM 依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>
3、Eureka 配置
# 设置服务端口
server.port=7777
# 设置服务地址
server.address=192.168.3.71
#是否将自己注册到eureka-server中,默认的为true
eureka.client.registerwitheureka=false
#是否从eureka-server中获取服务注册信息,默认为true
eureka.client.fetchregistry=false
#关闭自我保护
eureka.server.enable-self-preservation=false
#启用主动失效,并且每次主动失效检测间隔为5s
eureka.server.eviction-interval-timer-in-ms=5000
4、开启基于http basic的安全认证
4.1、POM依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>
4.2、配置
# 开启基于http basic的安全认证
spring.security.basic.enabled=true
# 设置安全认证用户名
spring.security.user.name=admin
# 设置安全认证密码
spring.security.user.password=********
4.3、说明
新版的security默认启用了csrf检验,需在eureka服务端配置security的csrf检验为false,示例如下:
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 WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
super.configure(http);
}
}