IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Java Discussion :

Problème avec Spring et le bean SessionFactory


Sujet :

Spring Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Développeur Java Débutant
    Inscrit en
    Juin 2013
    Messages
    22
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Développeur Java Débutant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2013
    Messages : 22
    Par défaut Problème avec Spring et le bean SessionFactory
    Bonsoir,
    Je réalise actuellement une application web qui utilise Spring Hibernate JSF et MySQL ...
    Lorsque je veut lancer mon application depuis NetBeans 7.3.1 j'ai le message "SEVERE" suivant :

    SEVERE: Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.springframework.web.context.ContextLoaderListener
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tazaSessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
    Voici mon 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
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
     
    <?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"
           xmlns:p="http://www.springframework.org/schema/p" 
           xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
    	http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    	http://www.springframework.org/schema/context
    	http://www.springframework.org/schema/context/spring-context-3.1.xsd
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
     
     
        <!-- Data source access-->
        <bean id="tazaDataSource"
              class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
            <property name="url" value="jdbc:mysql://localhost:3306/Taza"/>
            <property name="username" value="root"/>
            <property name="password" value="007micke"/>
        </bean>
     
     
        <bean id="tazaSessionFactory" 
                  class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" 
                  p:dataSource-ref="tazaDataSource" p:packagesToScan="fr.itldev.model"> 
            <property name="hibernateProperties"> 
                <value> 
                    hibernate.format_sql=true 
                    hibernate.dialect=org.hibernate.dialect.MySQLDialect 
                    hibernate.hbm2ddl.auto=create 
                </value> 
            </property> 
        </bean> 
     
        <bean id="transactionManager"
              class="org.springframework.orm.hibernate4.HibernateTransactionManager">
            <property name="sessionFactory" ref="tazaSessionFactory"/>
        </bean>
     
        <tx:annotation-driven transaction-manager="transactionManager" />
     
     
        <!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->
        <context:component-scan base-package="fr.itldev.tazaWebapp"/>
     
    </beans>
    Voilà pour le moment, merci d'avance pour toute l'aide.

  2. #2
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Par défaut
    Bonjour,
    Utilise la version 3.1.

    Essaie avec

    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
     <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.hbm2ddl.auto">create</prop> 
                    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                    <prop key="hibernate.format_sql">true</prop>
                </props>
    </property>

    A+.

  3. #3
    Membre averti
    Homme Profil pro
    Développeur Java Débutant
    Inscrit en
    Juin 2013
    Messages
    22
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Développeur Java Débutant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2013
    Messages : 22
    Par défaut
    Bonjour,
    Et merci andry.aime pour ta réponse.
    j'ai fais les modification dans le bean ainsi que dans "xsi:schemaLocation" mais le problème persiste.

    J'ai finalement choisi le système D (comme dégonflé), j'ai repris le fichier applicationContext.xml fournis par mon tuteur lors de mon stage et j'ai supprimé tout ce qui été lié aux applications internes.

    çà donne çà :
    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"?>
    <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"
           xmlns:p="http://www.springframework.org/schema/p" 
           xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
    	http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    	http://www.springframework.org/schema/context
    	http://www.springframework.org/schema/context/spring-context-3.1.xsd
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
     
            <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
            <property name="jndiName" value="java:comp/env/jdbc/taza" />
        </bean>
     
         <!--Gestionnaire de persistence Unit--> 
        <bean id="pum" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager"
              p:persistenceXmlLocations="classpath:persistence.xml"
              p:defaultDataSource-ref="dataSource" />
     
        <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" p:dataSource-ref="dataSource">
            <property name="persistenceUnitManager" ref="pum"/>
            <property name="jpaVendorAdapter">
                <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
                      p:databasePlatform="org.hibernate.dialect.MySQL5InnoDBDialect" p:showSql="true">
                </bean>
            </property>
        </bean>
     
         <!--le gestionnaire de transactions--> 
        <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
              p:entityManagerFactory-ref="entityManagerFactory" p:validateExistingTransaction="true">
        </bean>
     
        <context:annotation-config />
        <tx:annotation-driven mode="aspectj" transaction-manager="transactionManager" />
     
         <!--annotations de persistance--> 
        <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
     
         <!--traduction des exceptions--> 
        <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
     
        <!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->
        <context:component-scan base-package="fr.itldev.tazaWebapp"/>
     
    </beans>
    Maintenant il faut que je trouve comment expliquer ce micmac sans avoir l'air d'un pro du système D.

    Donc si quelq'un à une idée sur la façon de présenter çà je suis preneur et il aura toute ma gratitude pour avoir contribué à l'obtention de mon titre de développeur.

  4. #4
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    tu veux dire que tu ne comprends pas ce que fait ton xml?

  5. #5
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    Code xml : 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
     
    <?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"
           xmlns:p="http://www.springframework.org/schema/p" 
           xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
    	http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    	http://www.springframework.org/schema/context
    	http://www.springframework.org/schema/context/spring-context-3.1.xsd
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
    <!-- On importe différent namespace qui correspondent à différentes fonctionnalités de spring dont on a besoin. xml standard--> 
     
            <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
            <property name="jndiName" value="java:comp/env/jdbc/taza" />
        </bean>
    <!-- on définit un bean appelé "dataSource" qui est récupéré depuis le jndi du conteneur à l'endroit indiqué -->
     
         <!--Gestionnaire de persistence Unit--> 
        <bean id="pum" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager"
              p:persistenceXmlLocations="classpath:persistence.xml"
              p:defaultDataSource-ref="dataSource" />
    <!-- on définit un persistence unit appelé pum, de type jpa et configuré à partir du persistence.xml. On lui passe aussi en paramètre la datasource à utiliser -->
        <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" p:dataSource-ref="dataSource">
            <property name="persistenceUnitManager" ref="pum"/>
            <property name="jpaVendorAdapter">
                <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
                      p:databasePlatform="org.hibernate.dialect.MySQL5InnoDBDialect" p:showSql="true">
                </bean>
            </property>
        </bean>
    <!-- on définit un entity manager spring, de type hibernate, et utilisant le persistence unit mentionn -->
     
         <!--le gestionnaire de transactions--> 
        <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
              p:entityManagerFactory-ref="entityManagerFactory" p:validateExistingTransaction="true">
        </bean>
    <!-- on en récupère le transaction manager -->
     
        <context:annotation-config />
    <!-- on dit à spring qu'il faut tenir compte des annotations spring -->
        <tx:annotation-driven mode="aspectj" transaction-manager="transactionManager" />
    <!-- et on précise comment gérer les annotations de transaction -->
     
         <!--annotations de persistance--> 
        <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
    <!-- un bean qui doit probablement être injecté quelque part -->
     
         <!--traduction des exceptions--> 
        <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
     
    <!-- un bean qui doit probablement être injecté quelque part -->
     
        <!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->
        <context:component-scan base-package="fr.itldev.tazaWebapp"/>
    <!-- les packages à scanner pour les annotations -->
    </beans>

  6. #6
    Membre averti
    Homme Profil pro
    Développeur Java Débutant
    Inscrit en
    Juin 2013
    Messages
    22
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Développeur Java Débutant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2013
    Messages : 22
    Par défaut
    Bonjour tchize_,
    Et 1000 pour ta réponse.
    Du coup je me sens un peut crétin en relisant mon message. Car même si je débute en Spring (disons même dans le développement), je me rends compte qu'avec le ventre plein tout paré plus clair, aussi çà faisait depuis 5 jours en non-stop (sauf pour dormir) que j'étais sur ce machin et mon ami "le moteur de recherche qui commence par G".
    Et tout à l'heure j'étais un peut comme çà


    Merci encore à toi et à andry.aime.

  7. #7
    Membre averti
    Homme Profil pro
    Développeur Java Débutant
    Inscrit en
    Juin 2013
    Messages
    22
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Développeur Java Débutant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2013
    Messages : 22
    Par défaut
    Bonjour à tous,
    Je pensez avoir résolut mon problème mais finalement non le nouveau applicationContext.xml que j'avais mis en place ne va toujours pas mais au moins je n'est plus les même messages d'erreur.

    J'ai maintenant le message suivant :
    SEVERE: Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.springframework.web.context.ContextLoaderListener
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataMaquette': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: fr.itldev.service.TazaServiceImpl fr.itldev.tazaWebapp.data.DataMaquette.tazaService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [fr.itldev.service.TazaServiceImpl] is defined: Unsatisfied dependency of type [class fr.itldev.service.TazaServiceImpl]: expected at least 1 matching bean
    et voici le début de la classe citée dans le log + une des utilisation de TazaService :
    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
     
    @Service
    public class DataMaquette implements Serializable{
     
        private org.apache.log4j.Logger logger=org.apache.log4j.Logger.getLogger(this.getClass());
        private Projet projetCourant;
        private Projet projet1;
        private Projet projet2;
        private DerCommit commit1;
        private DerCommit commit2;
        private HistoBuild build;
        public List<Projet> projets;
        private List<HistoBuild> builds;
        private String login;
     
        @Autowired
        TazaServiceImpl tazaService;
        @PersistenceContext
        protected EntityManager entityManager;
     
    //  ........
        public List<Projet> getProjets() {
            this.projets = new ArrayList<Projet>();
            try {
                projets = tazaService.listerProjets();
            } catch (Exception e) {
                logger.error("Erreur de listing des projets : " + e.toString());
            }
            return projets;
        }
    Je ne sais pas si çà peut être aussi la cause du problème mais j'ai aussi annoté TazaServiceImp avec @Service (c'est ma classe service dans le package TazaSource).

    Je peux fournir plus de détail sur demande.

    Merci d'avance pour vos réponses.

Discussions similaires

  1. [Batch] Problème avec Spring Batch
    Par meriem15 dans le forum Spring
    Réponses: 6
    Dernier message: 16/12/2009, 16h41
  2. Réponses: 0
    Dernier message: 06/08/2009, 16h10
  3. [Framework] Problème avec Spring AOP
    Par yashiro dans le forum Spring
    Réponses: 1
    Dernier message: 09/06/2009, 17h12
  4. Problème avec Spring Plugin
    Par H-bil dans le forum Struts 1
    Réponses: 3
    Dernier message: 16/12/2008, 14h21
  5. Problème avec Spring : java.io.FileNotFoundException
    Par lionel84 dans le forum Spring
    Réponses: 6
    Dernier message: 29/08/2008, 09h59

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo