Bonjour,

je suis débutant en Spring et je tente d'injecter une DAO automatiquement dans mon projet en utilisant Spring/Hibernate mais je n'y arrive pas. Voici mes classes :

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
 
package com.test.bean
 
@Component
@ManagedBean
@RequestScope
public class Formulaire
{
    @Autowired
    private PersonneDAO prsDAO;
 
     public String submit()
     {
        if(prsDAO == null)
            System.out.println("dao null");
        return null;
    }
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
 
package com.test.dao
 
public class PersonneHDAO implements PersonneDAO
{
    @Autowired
    private LocalSessionFactoryBean sessionFactory;
}
Dans mon fichier de configuration de Spring, j'ai mis :

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
 
<context:component-scan base-package="com.test"/>
 
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="xxx"/>
        <property name="url" value="xxx"/>
        <property name="username" value="xxx"/>
        <property name="password" value="xxx"/>
    </bean>
 
    <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="packagesToScan" value="com.test"/>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">validate</prop>
                <prop key="hibernate.connection.autocommit">false</prop>
                <prop key="debug">true</prop>
            </props>
        </property>
    </bean>
Lorsque je lance la méthode submit de mon formulaire, il m'indique "dao null" ce qui m'indique que la création de mon DAO ne s'est pas effectué...

Merci d'avance