Bonjour,
J'ai un problème lorsque j'essaie d'injecter un bean dans une de mes classes.
L'erreur est la suivante :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [core.service.system.IUserService] 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), @org.springframework.beans.factory.annotation.Qualifier(value=userService)} at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1301) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1047) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533) ... 37 more
Ma classe BasicService :
Ma classe UserService :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 @Transactional(readOnly = true) public abstract class BasicService<T extends BasicObject> implements IBasicService<T> { @Autowired protected IUserService userService; protected IBasicDAO<T> basicDAO; public IUserService getUserService() { return userService; } public void setUserService(IUserService userService) { this.userService = userService; } /** * @return the basicDAO */ public IBasicDAO<T> getBasicDAO() { return basicDAO; } /** * @param basicDAO the basicDAO to set */ public void setBasicDAO(IBasicDAO<T> basicDAO) { this.basicDAO = basicDAO; } ...
Mon fichier spring-context :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 @Service @Transactional(readOnly = true) public class UserService extends BasicService<User> implements IUserService { @Autowired private IUserDAO userDAO; public IUserDAO getUserDAO() { return userDAO; } public void setUserDAO(IUserDAO userDAO) { this.userDAO = userDAO; } ...
Je me demande si le problème ne viendrai pas du fait que j'utilise le bean UserService dans la classe mere de UserService (BasicService).
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 <?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:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xsi:schemaLocation= "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:annotation-config /> <context:component-scan base-package="core.dao, core.service"/> <bean id="userService" class="core.service.system.UserService" /> <!-- Session Factory Declaration --> <bean id="SessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="configLocation" value="classpath:hibernate.cfg.xml"/> </bean> <!-- Enable the configuration of transactional behavior based on annotations --> <tx:annotation-driven transaction-manager="txManager"/> <!-- Transaction Manager is defined --> <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="SessionFactory"/> </bean> </beans>
J'utilise Spring Tool Suite, je sais pas si la vue Spring Explorer un bon indicateur de l'existence des beans réfférencés dans l'appli, auquel cas mon UserService est bien présent.
Si vous avez des pistes je suis preneur. Merci
Partager