springboot版本是 Hoxton.SR3
Eureka服務添加security客戶端不能註冊的錯誤
服務端配置application.yml
server:
port: 8000
spring:
application:
name: eureka-server
security:
user:
name: user
password: admin
eureka:
instance:
hostname: 127.0.0.1
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://127.0.0.1:8000/eureka/
在eureka服務端添加配置文件 去除csrf驗證
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf ().disable ().authorizeRequests ().anyRequest ().authenticated ().and ().httpBasic ();
}
}
在客戶端修改連接eureka地址
server:
port: 8001
spring:
application:
name: client-server
eureka:
instance:
hostname: 127.0.0.1
client:
service-url:
#user:admin是在eureka服務端設置的賬號密碼
defaultZone: http://user:[email protected]:8000/eureka/