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