網站首頁 編程語言 正文
SpringSecurity Oauth2 解決 The bean ‘metaDataSourceAdvisor‘, defined in null, could not be registered.
作者:Jothan Zhong 更新時間: 2024-01-07 編程語言The bean ‘metaDataSourceAdvisor’, defined in null, could not be registered.
安全配置
/**
* @Classname: HMall
* @Date: 2019-9-27 14:49
* @Author: 98
* @Description:
*/
@Configuration
@EnableWebSecurity
//方法攔截
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, jsr250Enabled = true)
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Bean
public BCryptPasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Bean
@Override
protected UserDetailsService userDetailsService(){
return new UserDetailsServiceImpl();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService());
}
/**
* 需要配置這個支持password模式
* support password grant type
* @return
* @throws Exception
*/
@Override
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
}
1234567891011121314151617181920212223242526272829303132333435363738394041
認證服務器
/**
* @Classname: HMall
* @Date: 2019-9-27 13:13
* @Author: 98
* @Description: 認證服務器
*/
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter {
@Autowired
private BCryptPasswordEncoder passwordEncoder;
/**
* 注入authenticationManager
* 來支持 password grant type
*/
@Autowired
private AuthenticationManager authenticationManager;
/**
* 注入authenticationManager
* 來支持 password grant type
*/
@Override
public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
oauthServer
.tokenKeyAccess("permitAll()") //url:/oauth/token_key,exposes public key for token verification if using JWT tokens
.checkTokenAccess("isAuthenticated()") //url:/oauth/check_token allow check token
.allowFormAuthenticationForClients();
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.authenticationManager(authenticationManager);
}
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("client")
.secret(passwordEncoder.encode("123456"))
.authorizedGrantTypes("password", "refresh_token")
.scopes("app")
.resourceIds("oauth2-resource")
.accessTokenValiditySeconds(60*60*24)
.refreshTokenValiditySeconds(60*60*24*30);
}
}
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
原因
因為有了重復的bean注冊,只需要在配置文件中加入以下代碼:
# 遇到相同名字時,是否允許覆蓋注冊
main:
allow-bean-definition-overriding: true
123
原文鏈接:https://blog.csdn.net/qq_43985303/article/details/135377387
- 上一篇:沒有了
- 下一篇:沒有了
相關推薦
- 2023-11-16 當pytorch找不到 CUDA 時,如何修復錯誤:版本 libcublasLt.so.11 未在帶
- 2023-01-09 python自動化測試中裝飾器@ddt與@data源碼深入解析_python
- 2022-06-02 C語言?隊列的實現全解析_C 語言
- 2023-04-19 Android使用gradle讀取并保存數據到BuildConfg流程詳解_Android
- 2022-07-21 微信小程序--動態設置導航欄顏色
- 2021-12-12 Redis實現分布式鎖的實例講解_Redis
- 2023-01-01 echarts-xAxis-底部文字傾斜
- 2022-12-12 Android?DataBinding類關系深入探究_Android
- 欄目分類
-
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支