注冊中心配置了spring?security后客戶端啟動(dòng)報(bào)錯(cuò)
問題
注冊中心配置了security后, 報(bào)了 registration failed Cannot execute request on any known server 的錯(cuò)誤, 原因是 2.1版本的security默認(rèn)加上了 csrf 攔截, 所以需要通過重寫方法, 把csrf攔截禁用
解決
在啟動(dòng)類上加上以下代碼(禁用csrf)即解決問題
@EnableWebSecurity
static class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.httpBasic();
}
}完整代碼
/**
* @author 毛宇鵬
*/
@EnableEurekaServer
@SpringBootApplication(exclude={
DataSourceAutoConfiguration.class,
HibernateJpaAutoConfiguration.class
})
public class RegisterApplication {
public static void main(String[] args) {
SpringApplication.run(RegisterApplication.class, args);
}
/**
* 2.1版本的security默認(rèn)加上了 csrf 攔截, 所以需要通過重寫方法, 把csrf攔截禁用
* 參考: https://github.com/spring-cloud/spring-cloud-netflix/issues/2754
* <pre>
* This is because @EnableWebSecurity is now added by default when Spring Security is on the classpath.
* This enable CSRF protection by default. You will have the same problem in 1.5.10 if you add @EnableWebSecurity.
* One work around, which is not the most secure workaround if you have browsers using the Eureka dashboard, is to disable CSRF protection.
* This can be done by adding the following configuration to your app.
* </pre>
*/
@EnableWebSecurity
static class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.httpBasic();
}
}
}以上就是注冊中心配置了spring security后客戶端啟動(dòng)報(bào)錯(cuò)的詳細(xì)內(nèi)容,更多關(guān)于注冊中心配置spring security報(bào)錯(cuò)的資料請關(guān)注腳本之家其它相關(guān)文章!
- SpringBoot?整合Security權(quán)限控制的初步配置
- Spring?Security自定義登錄頁面認(rèn)證過程常用配置
- SpringBoot2.7?WebSecurityConfigurerAdapter類過期配置
- Spring Security實(shí)現(xiàn)禁止用戶重復(fù)登陸的配置原理
- spring security動(dòng)態(tài)配置url權(quán)限的2種實(shí)現(xiàn)方法
- SpringBoot + Spring Security 基本使用及個(gè)性化登錄配置詳解
- Spring?Security?OAuth?Client配置加載源碼解析
相關(guān)文章
解決java web應(yīng)用線上系統(tǒng)偶發(fā)宕機(jī)的情況
這篇文章主要介紹了解決java web應(yīng)用線上系統(tǒng)偶發(fā)宕機(jī)的情況,具有好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09
關(guān)于pom.xml中maven無法下載springcloud包問題
小編遇到這樣一個(gè)問題spring-cloud-starter-feign,spring-cloud-starter-eureka 一直無法下載,maven倉庫中包路徑顯示為unknown,怎么解決呢?下面小編給大家?guī)砹藀om.xml中maven無法下載springcloud包問題,需要的朋友可以參考下2022-08-08
SpringCloud的@RefreshScope 注解你了解嗎
這篇文章主要介紹了Spring Cloud @RefreshScope 原理及使用,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-09-09
SpringBoot中版本兼容性處理的實(shí)現(xiàn)示例
SpringBoot版本兼容性問題通常是由于依賴庫與SpringBoot版本不兼容引起的,本文主要介紹了SpringBoot中版本兼容性處理的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的可以了解一下2024-07-07
Java基于外觀模式實(shí)現(xiàn)美食天下食譜功能實(shí)例詳解
這篇文章主要介紹了Java基于外觀模式實(shí)現(xiàn)美食天下食譜功能,較為詳細(xì)的講述了外觀模式的概念、原理并結(jié)合實(shí)例形似詳細(xì)分析了Java基于外觀模式實(shí)現(xiàn)美食天下食譜功能的具體操作步驟與相關(guān)注意事項(xiàng),需要的朋友可以參考下2018-05-05
SpringBoot實(shí)現(xiàn)嵌入式 Servlet容器
傳統(tǒng)的Spring MVC工程部署時(shí)需要將WAR文件放置在servlet容器的文檔目錄內(nèi),而Spring Boot工程使用嵌入式servlet容器省去了這一步驟,本文就來設(shè)置一下相關(guān)配置,感興趣的可以了解一下2023-12-12
SpringBoot的ConfigurationProperties或Value注解無效問題及解決
在SpringBoot項(xiàng)目開發(fā)中,全局靜態(tài)配置類讀取application.yml或application.properties文件時(shí),可能會(huì)遇到配置值始終為null的問題,這通常是因?yàn)樵趧?chuàng)建靜態(tài)屬性后,IDE自動(dòng)生成的Get/Set方法包含了static關(guān)鍵字2024-11-11
spring boot使用RabbitMQ實(shí)現(xiàn)topic 主題
本篇文章主要介紹了spring boot使用RabbitMQ實(shí)現(xiàn)topic 主題,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-03-03

