網站首頁 編程語言 正文
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-01-28 架構師說比起404我們更怕200錯誤_相關技巧
- 2022-04-28 Python中turtle.write方法使用說明_python
- 2022-03-31 C#實現學生檔案查詢_C#教程
- 2022-09-21 Python腳本開發中的命令行參數及傳參示例詳解_python
- 2022-05-22 Nginx服務LNMP之WordPress部署流程步驟_nginx
- 2022-12-26 python?QT界面關閉線程池的線程跟隨退出完美解決方案_python
- 2022-11-10 pytorch人工智能之torch.gather算子用法示例_python
- 2022-11-20 Python實現Tracert追蹤TTL值的方法詳解_python
- 欄目分類
-
- 最近更新
-
- 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同步修改后的遠程分支