Bonjour !

Je commence depuis peu Spring et je dois dire que là je bloque!
J'ai suivi le tutoriel disponible à cette url : http://baptiste-meurant.developpez.c...ing-hibernate/

Non sans modifier un peu le nom des classes pour que ça colle avec ma table.
Je souhaite simplement faire un formulaire html qui me permette de définir si le couple login/password est correct et si oui mettre en session l'utilisateur.

J'ai donc ces fichiers :

ApplicationContextDao.xml

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
 
<!-- Application context DAO layer -->
 
<beans>
 
    <!-- sessionFactory  -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="configLocation">
            <value>classpath:hibernate.cfg.xml</value>
        </property>
        <property name="annotatedClasses">
            <list>
                <value>com.ww.model.annoted.Acces</value>
            </list>
        </property>
    </bean>
 
    <!-- General  -->
    <bean id="accesDao" class="com.ww.dao.hibernate3.AccesDaoImpl">
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        </property>
    </bean>
 
    <!-- transactionManager  -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        </property>
    </bean>
 
    <bean id="transactionProxy" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
        <property name="transactionManager">
            <ref bean="transactionManager"/>
        </property>
        <property name="transactionAttributes">
            <props>
                <prop key="insert*">PROPAGATION_REQUIRED</prop>
                <prop key="update*">PROPAGATION_REQUIRED</prop>
                <prop key="save*">PROPAGATION_REQUIRED</prop>
                <prop key="*">PROPAGATION_REQUIRED, readOnly</prop>
            </props>
        </property>
    </bean>
 
 
</beans>
ApplicationContext.xml

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
 
<?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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
 
    <bean id="accesManagerTarget" class="com.ww.service.impl.AccesManagerImpl">
        <property name="accesDao">
            <ref bean="accesDao" />
        </property>
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        </property>
    </bean>
 
    <bean id="accesManager" parent="transactionProxy">
        <property name="target">
            <ref bean="accesManagerTarget"/>
        </property>
        <property name="transactionAttributeSource">
            <bean class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"/>
        </property>
    </bean>
 
</beans>
com/ww/service/AccesManager.java

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
31
32
33
34
35
36
37
 
package com.ww.service;
 
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
 
import com.ww.model.Acces;
 
@Transactional (readOnly=true, propagation=Propagation.REQUIRED)
public interface AccesManager {
 
    /**
     * Check if the login exists and if the password is correct. 
     * @param login : user login
     * @param password : user password
     * @return true if the login exists and if the password is correct. 
     * Otherwise, return false. 
     */
    public boolean checkLogin (String login, String password);
 
    /**
     * Return a User object from a given login.
     * @param login : user login
     * @return the corresponding user object.
     */
    public Acces getUser(String login);
 
    /**
     * Change the password to 'password' for the given login
     * @param login : user login
     * @param password : user new password
     * @return the new User object
     */
    @Transactional (readOnly=false)
    public Acces changePassword (String login, String password);
 
}
com/ww/dao/hibernate3/AccesDaoImpl.java

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
 
package com.ww.dao.hibernate3;
 
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
 
import com.ww.dao.AccesDao;
import com.ww.model.Acces;
 
public class AccesDaoImpl extends HibernateDaoSupport implements AccesDao {
 
    @Override
    public boolean checkLogin(String login, String password) {
        if (null == login || null == password) {
            throw new IllegalArgumentException("Login and password are mandatory. Null values are forbidden.");
        }       
        try {
            logger.info("Check user with login: "+login+" and password : [PROTECTED]");
            Session session = getSessionFactory().getCurrentSession();
            // create a new criteria
            Criteria crit = session.createCriteria(Acces.class);
            crit.add(Restrictions.eq("loginUser", login));
            crit.add(Restrictions.eq("passwordUser", password));
 
            Acces user = (Acces)crit.uniqueResult();
            return (user != null);
        }
        catch(DataAccessException e) {
            // Critical errors : database unreachable, etc.
            logger.error("Exception - DataAccessException occurs : "+e.getMessage()
                    +" on complete checkLogin().");
            return false;
        }
    }
 
    @Override
    public Acces getUser(String login) {
        if (null == login) {
            throw new IllegalArgumentException("Login is mandatory. Null value is forbidden.");
        }
        try {
            logger.info("get User with login: "+login);
            Session session = getHibernateTemplate().getSessionFactory().getCurrentSession();
            // create a new criteria
            Criteria crit = session.createCriteria(Acces.class);
            crit.add(Restrictions.eq("loginUser", login));
 
            Acces user = (Acces)crit.uniqueResult();
            return user;
        }
        catch(DataAccessException e) {
            // Critical errors : database unreachable, etc.
            logger.error("Exception - DataAccessException occurs : "+e.getMessage()
                    +" on complete getUser().");
            return null;
        }
    }
 
}
Lors de l'appel à la méthode getCurrentSession(); il m'envoie une jolie Exception de ce genre...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
 
Caused by: org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
	at org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63)
	at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:622)
	at com.ww.dao.hibernate3.AccesDaoImpl.checkLogin(AccesDaoImpl.java:21)
	at com.ww.service.impl.AccesManagerImpl.checkLogin(AccesManagerImpl.java:29)
	at com.ww.servlet.UserServlet.checkLogin(UserServlet.java:99)
	... 20 more
J'ai donc regardé de plus près ce que me renvoyait getSessionFactory() et une chose me choque... c'est que le membre transactionManager est null alors que je l'ai définit dans ApplicationContextDao.xml.

Qqun saurait m'aiguiller pour résoudre ce problème ?

Merci