Problème accès DAO entre Struts 2 et Spring
Bonjour
J'essaie de faire communiquer struts2/hibernate et spring. Le problème survient lorsque j'appelle ma couche dao depuis mon action struts qui lève un nullpointerexception.
Au démarrage, spring ne lance aucune erreur.
Mon erreur
Citation:
java.lang.NullPointerException
at com.spring.context.StaticSpringApplicationContext.getDao(StaticSpringApplicationContext.java:34)
at com.dao.hibernate.DaoHelper.getDao(DaoHelper.java:14)
at com.dao.hibernate.DaoHelper.getLivreDao(DaoHelper.java:10)
at librairie.RechercheLivreAction.execute(RechercheLivreAction.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
applicationContext.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>com/hibernate/config/mapping/Publieur.hbm.xml</value>
<value>com/hibernate/config/mapping/Langue.hbm.xml</value>
<value>com/hibernate/config/mapping/Livre.hbm.xml</value>
<value>com/hibernate/config/mapping/TypeLivre.hbm.xml</value>
<value>com/hibernate/config/mapping/Auteur.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
</props>
</property>
</bean>
<bean id="livreDao" class="com.dao.hibernate.impl.LivreDaoImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="rechercheLivreAction" class="librairie.RechercheLivreAction">
<property name="livreDao" ref="livreDao"/>
</bean> |
RechercheLivreAction.java
Code:
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
| public class RechercheLivreAction extends LibrairieSupport {
private static final long serialVersionUID = -7966777564300031486L;
private String nom;
private Livre livre;
private LivreDao livreDao;
public String execute() throws Exception {
List list = livreDao.getLivre( this.livre ); // L'ERREUR est ici livreDao est null
if( list.size() > 0 )
System.out.println("OK");
setMessage(getText("TEST", "0" , new String[] { String.valueOf(list.size() ) }));
return SUCCESS;
}
LivreDaoImpl.java
public class LivreDaoImpl extends HibernateDaoSupport implements LivreDao {
@Resource(name = "sessionFactory")
private SessionFactory sessionFactory;
public void setSessionfactory(SessionFactory sessionfactory) {
this.sessionFactory = sessionfactory;
}
@Override
public List listeLivre() {
Session session = null;
session = sessionFactory.openSession();
List emp = null; |