@Configuration
@EnableWebSecurity
public class SamlSecurityConfig extends WebSecurityConfigurerAdapter {
@Bean(value = "myWebSSOProfile")
public WebSSOProfile webSSOprofile() {
return new WebSSOProfileImpl();
}
@Bean
public SAMLEntryPoint samlEntryPoint() {
SAMLEntryPoint samlEntryPoint = new SAMLEntryPoint();
samlEntryPoint.setDefaultProfileOptions(mydefalutWebSSOProfileOptions());
return samlEntryPoint;
}
}
ERROR o.s.boot.web.embedded.tomcat.TomcatStarter -Error starting Tomcat context. Exception:
org.springframework.beans.factory.UnsatisfiedDependencyException.
Message: Error creating bean with name 'samlEntryPoint': Unsatisfied dependency expressed through method 'setWebSSOprofile' parameter 0;
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type
'org.springframework.security.saml.websso.WebSSOProfile' available: expected at least 1 bean which
qualifies as autowire candidate. Dependency annotations: {}
根据异常可以看出是public SAMLEntryPoint samlEntryPoint() 这个bean报错了.
其中有一句method ‘setWebSSOprofile’ parameter 0…, 进入类查看这个方法如下:
发现这个类依赖了一个bean, 且名称为"webSSOprofile", 而我们自定义的配置类中,bean的名称为"myWebSSOProfile":
@Bean(value = "webSSOprofile")
public WebSSOProfile webSSOprofile() {
return new WebSSOProfileImpl();
}
该问题需要仔细分析异常,并了解注解的原理,方可快速定位问题.