我正在尝试在我的项目中实现spring-security和spring-saml模块,但是面临与自动连接失败相关的以下错误。
(我的Spring核心和安全罐都是3.1.2,spring-saml jar是1.0.0。)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'samlEntryPoint': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.saml.SAMLEntryPoint.setWebSSOprofile(org.springframework.security.saml.websso.WebSSOProfile); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.springframework.security.saml.websso.WebSSOProfile] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
... 52 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.saml.SAMLEntryPoint.setWebSSOprofile(org.springframework.security.saml.websso.WebSSOProfile); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.springframework.security.saml.websso.WebSSOProfile] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:593)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)
... 60 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.springframework.security.saml.websso.WebSSOProfile] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:952)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:821)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:735)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:551)
... 62 more
我在我创建的security.xml中检查了与autoscan相关的设置,并将其设置为
<context:component-scan base-package="org.springframework.security" />
我认为这是非常标准的,但是因为我认为在所有依赖类上进行自动扫描可能会更好。第二次猜测当然是我把它改成了
<context:component-scan base-package="org.springframework" />
但是在这样做时我得到了一个不同的错误 -
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor org.springframework.scheduling.annotation.ProxyAsyncConfiguration.asyncAdvisor()] threw exception; nested exception is java.lang.IllegalArgumentException: @EnableAsync annotation metadata was not injected
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:169)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:570)
... 26 more
Caused by: java.lang.IllegalArgumentException: @EnableAsync annotation metadata was not injected
at org.springframework.util.Assert.notNull(Assert.java:112)
at org.springframework.scheduling.annotation.ProxyAsyncConfiguration.asyncAdvisor(ProxyAsyncConfiguration.java:45)
at org.springframework.scheduling.annotation.ProxyAsyncConfiguration$$EnhancerByCGLIB$$dbf0f346.CGLIB$asyncAdvisor$0(<generated>)
at org.springframework.scheduling.annotation.ProxyAsyncConfiguration$$EnhancerByCGLIB$$dbf0f346$$FastClassByCGLIB$$4c1b9c21.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:167)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:280)
at org.springframework.scheduling.annotation.ProxyAsyncConfiguration$$EnhancerByCGLIB$$dbf0f346.asyncAdvisor(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:149)
... 27 more
我的应用程序使用了一个附加的上下文文件&amp;现在我也添加了安全性。
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/MbsOutContext.xml
/WEB-INF/securityContext.xml
</param-value>
你能告诉我我需要做些什么来纠正这个问题吗?
答案 0 :(得分:1)
我有同样的问题。解决方案是将“webSSOProfile”bean重命名为“webSSOprofile”(注意小写P)。在我这样做之后,它正确地启动了。
答案 1 :(得分:0)
您的bean(@Component, @Service, @Controller, ...
)确实位于包org.springframework.security
?
弹簧的扫描功能可以检测到&#34; custom&#34; bean自动并使用BeanDefinitions
注册相应的ApplicationContext
。它不适用于扫描框架本身以进行任何类型的引导。
因此,此配置应更像
<context:component-scan base-package="org.example"/>
您可以在参考资料中找到更多信息: https://docs.spring.io/spring/docs/3.0.0.M4/reference/html/ch03s10.html