security:
user:
name: xxx
password: xxx
配置了默認用戶名和密碼
然後eureka客戶端註冊地址也加上了
eureka:
client:
service-url:
defaultZone: http://xxx:xxx@localhost:8761/eureka/
結果啓動註冊的時候註冊不了,說是403錯誤.
然後看了下boot的文檔,在security處找到了一個說是csrf會導致403,我想可能服務註冊的403就是這個原因造成的.
之後又在github上的springCloud的issue上看到有人提了這個問題,一看的確是這個原因
處理方式就是禁用security的csrf咯,雖然這樣不太安全,不過我這個是提供rest接口,也用不上這個
@EnableWebSecurity
static class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);//加這句是爲了訪問eureka控制檯和/actuator時能做安全控制
http.csrf().disable();
}
}