Struts2+Spring+Hibernate

Struts2+Spring+Hibernate - Java - Programmation

Marsh Posté le 10-09-2012 à 16:03:26    

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
 
        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
 
 <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
 
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;

Reply

Marsh Posté le 10-09-2012 à 16:03:26   

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed