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 configuration datasource hibernate


Sujet :

Spring Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Février 2004
    Messages
    20
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Février 2004
    Messages : 20
    Par défaut Problème configuration datasource hibernate
    Bonjour à tous,

    Je suis en train de découvrir Spring et comme premier exercice j'essaye de simplement configurer une Datasource. J'utilise Spring 3.0.5, commons DBCP 1.3, Tomcat 6.0, Java 1.5, Hibernate et une base de données PostgreSQL. Voici mon fichier spring-context.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
    51
    52
     
    <?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:tx="http://www.springframework.org/schema/tx"
    	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-3.0.xsd
    			http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
     
    	<bean id="callVolumeDAO" class="be.ing.icc.daos.CallVolumeDAO" />
    	<bean id="service" class="be.ing.icc.services.CallVolumeService">
    		<property name="dao" ref="callVolumeDAO"></property>
    	</bean>
     
     	<!-- couche de persistance JPA -->
    	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    		<property name="dataSource" ref="dataSource" />
    		<property name="jpaVendorAdapter">
    			<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    				<!--
    				<property name="showSql" value="true" />
    				-->
    				<property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
    				<property name="generateDdl" value="true" />
    			</bean>
    		</property>
    	</bean>
     
    	<!-- la source de donnéees DBCP -->
    	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    		<property name="driverClassName" value="org.postgresql.Driver" />
    		<property name="url" value="jdbc:postgresql:ICCReports" />
    		<property name="username" value="iccreports" />
    		<property name="password" value="iccreports" />
    	</bean>
     
    	<!-- le gestionnaire de transactions -->
    	<tx:annotation-driven transaction-manager="txManager" />
    	<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    		<property name="entityManagerFactory" ref="entityManagerFactory" />
    	</bean>
     
    	<!-- traduction des exceptions -->
    	<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
     
    	<!-- annotations de persistance -->
    	<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
     
    	<context:annotation-config />
     
    </beans>
    Le problème que je rencontre c'est que quand je génère mon contexte Spring j'obtiens cette erreur:

    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
     
    org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'dataSource' must be of type [javax.persistence.EntityManagerFactory], but was actually of type [org.apache.commons.dbcp.BasicDataSource]
    	org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:349)
    	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    	org.springframework.orm.jpa.EntityManagerFactoryUtils.findEntityManagerFactory(EntityManagerFactoryUtils.java:107)
    	org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findNamedEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:510)
    	org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:492)
    	org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.resolveEntityManager(PersistenceAnnotationBeanPostProcessor.java:656)
    	org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.getResourceToInject(PersistenceAnnotationBeanPostProcessor.java:629)
    	org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:147)
    	org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
    	org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:338)
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    	org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
    	org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    	org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
    	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    	org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
    	org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
    	org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
    	org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    	org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    	be.ing.icc.servlets.CallVolumeMgmtServlet.loadCallVolumes(CallVolumeMgmtServlet.java:92)
    	be.ing.icc.servlets.CallVolumeMgmtServlet.doPost(CallVolumeMgmtServlet.java:80)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    Bon, l'erreur est "claire", LocalContainerEntityManagerFactoryBean s'attend à recevoir une instance de "javax.persistence.EntityManagerFactory" au lieu de "org.apache.commons.dbcp.BasicDataSource" pour son attribut dataSource. Mais quelle classe dois-je alors utiliser dans mon bean datasource? Ce que je ne comprend pas c'est que c'est ce genre de configuration que je trouve partout sur le net et personne ne semble renconter ce problème...

    Si quelqu'un pouvait éclairer ma lanterne ce serait sympa !

    Merci d'avance !

  2. #2
    Membre Expert
    Homme Profil pro
    Inscrit en
    Septembre 2006
    Messages
    2 963
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2006
    Messages : 2 963
    Par défaut
    Citation Envoyé par Clezio Voir le message
    Bonjour à tous,

    Je suis en train de découvrir Spring et comme premier exercice j'essaye de simplement configurer une Datasource. J'utilise Spring 3.0.5, commons DBCP 1.3, Tomcat 6.0, Java 1.5, Hibernate et une base de données PostgreSQL. Voici mon fichier spring-context.xml:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    xsi:schemaLocation="…spring-beans-2.5.xsd

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Février 2004
    Messages
    20
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Février 2004
    Messages : 20
    Par défaut
    Merci JeitEmgie!

    En effet, quand je corrige cette erreur je n'ai plus le problème mentionné, par contre mon fichier de configuration xml comporte 2 erreurs aux lignes suivantes:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    ...
    <tx:annotation-driven transaction-manager="txManager" />
    ...
    Avec comme erreur:

    cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'tx:annotation-driven'.
    - schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/tx/spring-tx-3.0.xsd', because 1) could not find the document; 2) the
    document could not be read; 3) the root element of the document is not <xsd:schema>.

    Et

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    ...
    <context:annotation-config />
    ...
    Avec comme erreur:

    Multiple annotations found at this line:
    - schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/context/spring-context-3.0.xsd', because 1) could not find the document;
    2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
    - cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'context:annotation-config'.

    Une idée?

    Merci encore !

  4. #4
    Membre Expert
    Homme Profil pro
    Inscrit en
    Septembre 2006
    Messages
    2 963
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2006
    Messages : 2 963

Discussions similaires

  1. [Data] Problème configuration datasource hibernate
    Par Clezio dans le forum Spring
    Réponses: 1
    Dernier message: 28/07/2011, 14h13
  2. [MyEclipse] Problème avec fichier configuration d'Hibernate
    Par psycho_xn dans le forum Eclipse Java
    Réponses: 2
    Dernier message: 25/08/2008, 11h47
  3. Hibernate problème configuration
    Par badreddine540 dans le forum Hibernate
    Réponses: 4
    Dernier message: 15/08/2008, 12h26
  4. Problème Configuration Hibernate-Eclipse
    Par salirose dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 02/04/2008, 23h58
  5. Réponses: 10
    Dernier message: 15/09/2007, 07h40

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