Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1595 connectés 

  FORUM HardWare.fr
  Programmation
  Java

  Struts2+Spring+Hibernate

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Struts2+Spring+Hibernate

n°2156230
Paulperson​ne820
Posté le 10-09-2012 à 16:03:26  profilanswer
 

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;

mood
Publicité
Posté le 10-09-2012 à 16:03:26  profilanswer
 


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Java

  Struts2+Spring+Hibernate

 

Sujets relatifs
Retrouver la structure hibernate en javaSPRING WEB MVC erreur lors d'un addobject
[resolue] impossible d'afficher des images sur un spring MVCHibernate + GWT = Serialization problem
Lien paramètres Struts2 (bean) - Applet[sitemesh] [Struts2] exclure page
[JAVA][HIBERNATE] Id via UserTypeHibernate java
design many to one hibernateProbleme hibernate Spring
Plus de sujets relatifs à : Struts2+Spring+Hibernate


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR