Frühjahr autowire nicht arbeiten, Keine Qualifikation bean des Typs Injektion von autowired Abhängigkeiten ist fehlgeschlagen;
Dieser Fehler erscheint immer wenn ich versuche meinen code.
Ich sah alle über google nach einer Antwort für die vergangene Woche, aber meine Klasse-Projekt ist bald fällig und ich brauche etwas Hilfe. Ich habe @service-und component-scan und ich habe implementiert die service-Klasse. Was sonst könnte das problem sein. Ich überprüfte alle über google. Ich habe zu viele Tage versucht zu Debuggen dieser Fehler ohne Erfolg, und mein Termin ist kommenden. Bitte um Hilfe, Sehr dankbar für jede Hilfe. 🙂
org.springframework.beans.factory.BeanCreationException: Error creating bean with name'springSecurityFilterChain' defined in ServletContext resource [/WEB-INF/spring/spring-security.xml]: Cannot resolve reference to bean 'userAuthenticationFilter' while setting bean property 'filterChainMap' with key [Root bean: class [org.springframework.security.web.util.AnyRequestMatcher]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with key [2]; nested exception is org.springframework.beans.factory.BeanCreationException:Error creating bean with name 'userAuthenticationFilter' defined in ServletContext resource [/WEB-INF/spring/spring-security.xml]: Cannot resolve reference to bean 'customAuthMgr' while setting bean property 'authenticationManager'; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'customAuthMgr' defined in ServletContext resource [/WEB-INF/spring/spring-security.xml]: Cannot resolve reference to bean 'authenticationProvider' while setting bean property 'providers' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authenticationProvider': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException:
Could not autowire field: protected a.b.c.d.projectName.service.UserInfoInterface a.b.c.d.projectName.springweb.security.UserAuthenticationProvider.userInfoInterface; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type [a.b.c.d.projectName.service.UserInfoInterface] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations:
{@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:329)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:353)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:154)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedMap(BeanDefinitionValueResolver.java:379)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:162)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1387)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1128)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:1681)
at com.ibm.ws.webcontainer.webapp.WebApp.commonInitializationFinish(WebApp.java:374)
at com.ibm.ws.webcontainer.webapp.WebAppImpl.initialize(WebAppImpl.java:299)
at com.ibm.ws.webcontainer.webapp.WebGroupImpl.addWebApplication(WebGroupImpl.java:100)
at com.ibm.ws.webcontainer.VirtualHostImpl.addWebApplication(VirtualHostImpl.java:166)
at com.ibm.ws.webcontainer.WSWebContainer.addWebApp(WSWebContainer.java:731)
at com.ibm.ws.webcontainer.WSWebContainer.addWebApplication(WSWebContainer.java:616)
at com.ibm.ws.webcontainer.component.WebContainerImpl.install(WebContainerImpl.java:376)
at com.ibm.ws.webcontainer.component.WebContainerImpl.start(WebContainerImpl.java:668)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:1122)
at com.ibm.ws.runtime.component.DeployedApplicationImpl.fireDeployedObjectStart(DeployedApplicationImpl.java:1315)
at com.ibm.ws.runtime.component.DeployedModuleImpl.start(DeployedModuleImpl.java:623)
at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:940)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:725)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:2046)
at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:439)
at com.ibm.ws.runtime.component.CompositionUnitImpl.start(CompositionUnitImpl.java:123)
at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:382)
at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.access$300(CompositionUnitMgrImpl.java:110)
at com.ibm.ws.runtime.component.CompositionUnitMgrImpl$CUInitializer.run(CompositionUnitMgrImpl.java:949)
at com.ibm.wsspi.runtime.component.WsComponentImpl$_AsynchInitializer.run(WsComponentImpl.java:349)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1550) Caused by: org.springframework.beans.factory.BeanCreationException:
//entity-Klasse
package a.b.c.d.projectName.domain.persistence;
import a.b.c.d.projectName.domain.TheRole;
@Entity
@NamedQueries({
@NamedQuery(name="UserInfo.findByUserID",
query="select . . ."
)
})
@Table(name="user_account")
public class UserInfo implements Serializable
{
private static final long serialVersionUID = 1L;
@Id
@Column(name = "userID", length = 20)
private String accountID;
@Column(name = "userDesc", length = 50)
private String userDesc;
//getters setters default constructor toString compare
@ManyToMany
@JoinTable(name="userAcct_userRoles",
joinColumns=@JoinColumn(name="userID"),
inverseJoinColumns=@JoinColumn(name="userRoleID"))
private Collection<TheRole> theRoles;
public Collection<TheRole> getRoles() {
return theRoles;
}
public void setRoles(Collection<TheRole> theRoles) {
this.theRoles = theRoles;
}
}
//Schnittstelle
package a.b.c.d.projectName.service;
import a.b.c.d.projectName.domain.persistence.UserInfo;
public interface UserInfoInterface {
public UserInfo getUserInfo(String userID);
}
//service-Klasse
package a.b.c.d.projectName.service.impl;
import a.b.c.d.projectName.domain.persistence.UserInfo;
import a.b.c.d.projectName.service.UserInfoInterface;
. . .
@Service
public class UserInfoImpl implements UserInfoInterface {
@PersistenceContext(unitName = "userInfoPersistenceUnit")
private EntityManager em;
//default constructor...
@Override
public UserInfo getUserInfo(String userID) {
return em.createNamedQuery("UserInfo.findByUserID", UserInfo.class)
.setParameter("userID", userID).getSingleResult();
}
}
//für die spring security
package a.b.c.d.projectName.security;
import a.b.c.d.projectName.domain.persistence.UserInfo;
import a.b.c.d.projectName.domain.persistence.TheRole;
import a.b.c.d.projectName.service.UserInfoInterface;
. . .
public class UserAuthenticationProvider implements AuthenticationProvider {
@Autowired
protected UserInfoInterface userInfoInterface; //<--spring does not likethis
. . . }
//web.xml
. . .
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:a/b/c/d/springconfig/spring-config.xml
WEB-INF/spring/spring-security.xml
</param-value>
</context-param>
. . .
<servlet>
<servlet-name>projectNameDispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/spring-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
. . .
<filter>
<filter-name>OpenEntityManagerInViewFilter</filter-name>
<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
</filter>
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenEntityManagerInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
//spring-config.xml
. . . .
<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />
<context:annotation-config />
<aop:aspectj-autoproxy />
<context:component-scan base-package="a.b.c.d.projectName" />
<mvc:annotation-driven>
<mvc:message-converters>
<bean
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="objectMapper" ref="customObjectMapper"/>
<property name="prefixJson" value="true" />
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="requireSession" value="false"/>
</bean>
<bean id="customObjectMapper" class="a.b.c.d.projectName.configuration.JacksonCustomObjectMapper"/>
<bean class="org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver"/>
//spring-security.xml
. . .
<bean id="springSecurityFilterChain" class="org.springframework.security.web.FilterChainProxy">
<security:filter-chain-map path-type="ant">
<security:filter-chain pattern="/**"
filters=". . . userAuthFilter,
. . ." />
</security:filter-chain-map>
</bean>
<bean id="userAuthFilter" class=". . .">
<property name="authenticationManager" ref="customAuthMgr" />
</bean>
<bean id="customAuthMgr" class="org.springframework.security.authentication.ProviderManager">
<property name="providers">
<list>
<ref local="userAuthenticationProvider" />
</list>
</property>
</bean>
<bean id="userAuthenticationProvider"
class="a.b.c.d.projectName.security.UserAuthenticationProvider">
</bean>
. . .
Here are the jar files I have
ehcache-core-2.4.6.jar
hibernate-jap-2.0-api-1.0.0.Final.jar
hibernate-validator-4.1.0.Final.jar
hibernate3.jar
jackson-core-asl-1.9.13.jar
jackson-mapper-asl-1.9.13.jar
spring-aop-3.2.4.RELEASE.jar
spring-aspects-3.2.4.RELEASE.jar
spring-beans-3.2.4.RELEASE.jar
spring-context-3.2.4.RELEASE.jar
spring-context-support-3.2.4.RELEASE.jar
spring-core-3.2.4.RELEASE.jar
spring-expression-3.2.4.RELEASE.jar
spring-jdbc-3.2.4.RELEASE.jar
spring-orm-3.2.4.RELEASE.jar
spring-oxm-3.2.4.RELEASE.jar
spring-security-acl-3.2.4.RELEASE.jar
spring-security-aspects-3.2.4.RELEASE.jar
spring-security-config-3.2.4.RELEASE.jar
spring-security-core-3.2.4.RELEASE.jar
spring-security-taglibs-3.2.4.RELEASE.jar
spring-security-web-3.2.4.RELEASE.jar
spring-tx-3.2.4.RELEASE.jar
spring-web-3.2.4.RELEASE.jar
spring-webmvc-3.2.4.RELEASE.jar
spring-xml-3.2.4.RELEASE.jar
here are the xml headers
//Spring-config.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
">
//spring-security.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
//web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
- Sie brauchen eine bean des Typs UserInfoInterface. Ich sehe, Sie haben eine Klasse dieser Art, aber ich glaube, es sollte kommentiert mit
@Bean
statt@Service
. Alternativ können Sie fügen Sie der bean-definition für die Klasse, in der Sie xml-config-Datei. @Bean
ist für@Configuration
bean-Methoden.@Service
ist ein@Component
Spezialisierung.- Alles scheint an Ort und Stelle sein..Du hast component-scan, haben Sie, @Service..Es ist.. Nur für die Testversion können Sie versuchen, autowire die Umsetzung selbst, statt die Schnittstelle? Nur um zu überprüfen, ob es so funktioniert?
- Nikhil: ich habe versucht, sah aber den gleichen Fehler 🙁 warum auf der Erde würde es nicht Spritzen? Glaubst du, ich bin fehlt eine jar-Datei?
- Ich fand diese Fehler direkt vor der bean-autowire-error: FEHLER: org.springframework.web.Kontext.ContextLoader - Kontext-Initialisierung fehlgeschlagen, Ist dies eine jar-Datei-Fehler oder ein web.xml config-xml-Fehler? glaubst du, es ist im Zusammenhang der jar-Datei-Versionen kollidieren? Hat jemand Ideen, es zu lösen? Ich bin wirklich verloren. Thx
- Ich habe den jar-Datei-Versionen habe ich in den build path und die xml-Datei-Header. Haben Sie alle Fehler sehen? thx
- Tut mir Leid für dich schreiben zu müssen Frühling an der uni/Hochschule. Scheint wie ein guter Weg, um Menschen aus Programmieren! Keine Sorge, es ist noch nicht alles, diese schmerzhafte und bizaare!
- Ich bin immer die gleichen hier, aber es funktioniert, wenn deaktivieren spring security aus web.xml .könnte ein retriction von der security-Filter.Wir freuen uns auf eine Antwort....Hoffe, das ist hilfreich.
Du musst angemeldet sein, um einen Kommentar abzugeben.
Fügen Sie diese zu Ihrem security.xml
arbeitete für mich..
Glück