eureka服务端添加security验证之后,client注册失败

问题:erueka服务端添加security验证之后,client注册失败:

  com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server

解决:

在eureke服务端添加配置:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {
// Configure HttpSecurity as needed (e.g. enable http basic).
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER);
http.csrf().disable();
//注意:为了可以使用 http://${user}:${password}@${host}:${port}/eureka/ 这种方式登录,所以必须是httpBasic,
// 如果是form方式,不能使用url格式登录
http.authorizeRequests().anyRequest().authenticated().and().httpBasic();

}
}

spring boot 使用
Security:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>

参考https://blog.csdn.net/qq_33802316/article/details/80677644

原文地址:https://www.cnblogs.com/Mr-xt/p/10220806.html