注冊(cè)中心配置了spring?security后客戶端啟動(dòng)報(bào)錯(cuò)
問題
注冊(cè)中心配置了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(); } } }
以上就是注冊(cè)中心配置了spring security后客戶端啟動(dòng)報(bào)錯(cuò)的詳細(xì)內(nèi)容,更多關(guān)于注冊(cè)中心配置spring security報(bào)錯(cuò)的資料請(qǐng)關(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)文章
SpringBoot整合Kaptcha實(shí)現(xiàn)圖片驗(yàn)證碼加減乘除功能
在開發(fā)Web應(yīng)用時(shí),驗(yàn)證碼是一個(gè)常見的功能,它可以幫助我們防止機(jī)器人的惡意操作,今天我們將學(xué)習(xí)如何使用Kaptcha生成圖片驗(yàn)證碼,并自定義驗(yàn)證碼內(nèi)容為100以內(nèi)的加減乘除運(yùn)算,感興趣的朋友跟隨小編一起看看吧2024-07-07SpringCloud?eureka(server)微服務(wù)集群搭建過程
這篇文章主要介紹了微服務(wù)SpringCloud-eureka(server)集群搭建,?項(xiàng)目搭建的主要步驟和配置就是創(chuàng)建項(xiàng)目和引入pom依賴,本文通過圖文示例代碼相結(jié)合給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-07-07IDEA 自帶的數(shù)據(jù)庫工具真的很牛(收藏版)
這篇文章主要介紹了IDEA 自帶的數(shù)據(jù)庫工具真的很牛(收藏版),本文以 IntelliJ IDEA/ Mac 版本作為演示,其他版本的應(yīng)該也差距不大,需要的朋友可以參考下2021-04-04如何利用grep-console插件使Intellij idea顯示多顏色調(diào)試日志
這篇文章主要介紹了利用grep-console插件使Intellij idea顯示多顏色調(diào)試日志,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-05-05