使用SpringSecurityOauth2启动异常:
ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘openIdAuthenticationSecurityConfig’: Unsatisfied dependency expressed through field ‘ygerAuthenticationSuccessHandler’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘ygerAuthenticationSuccessHandler’: Unsatisfied dependency expressed through field ‘authorizationServerTokenServices’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerEndpointsConfiguration’: Unsatisfied dependency expressed through field ‘configurers’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘ygerAuthorizationServerConfig’: Unsatisfied dependency expressed through field ‘authenticationManager’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.security.authentication.AuthenticationManager’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
2020-12-03 14:54:16.351 INFO 4512 — [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
解决办法:
核心上面已经标记出来,添加一个配置类就好了:
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
/**
* @author liurui
* @date 2019年11月25日
*/
@Configuration
public class ConfigurationUpdateBean extends WebSecurityConfigurerAdapter {
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
}