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

Hibernate Java Discussion :

[JUnit] Could not find datasource


Sujet :

Hibernate Java

  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    802
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 802
    Points : 653
    Points
    653
    Par défaut [JUnit] Could not find datasource
    Bonjour,

    J'essaye d'écrire un test unitaire pour un webservice. Le webservice fonctionne correctement lorsque mon serveur d'application tourne. Seulement je veux que mon test unitaire puisse tourner sans avoir besoin d'exécuter le serveur d'application.

    Le problème est que je tombe systématiquement sur cette erreur à l'exécution de mon test JUnit :
    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
     
    junit.framework.AssertionFailedError: Exception in constructor: testExcecute (org.hibernate.HibernateException: Could not find datasource
    	at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:56)
    	at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
    	at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
    	at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:414)
    	at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
    	at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
    	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
    	at com.bouygtel.renouvium.communrenouvium.util.hibernate.InitHibernate.initSessionFactory(InitHibernate.java:55)
    	at com.bouygtel.renouvium.controleur.servicetechnique.avenant.GenererAvenantPortTypeImplTest.<init>(GenererAvenantPortTypeImplTest.java:26)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
    	at junit.framework.TestSuite.createTest(TestSuite.java:131)
    	at junit.framework.TestSuite.addTestMethod(TestSuite.java:114)
    	at junit.framework.TestSuite.<init>(TestSuite.java:75)
    	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.getTest(JUnit3TestLoader.java:102)
    	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.loadTests(JUnit3TestLoader.java:59)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:445)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
    	at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
    	at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
    	at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
    	at javax.naming.InitialContext.lookup(InitialContext.java:351)
    	at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
    	... 21 more
    )
    	at junit.framework.Assert.fail(Assert.java:47)
    	at junit.framework.TestSuite$1.runTest(TestSuite.java:263)
    	at junit.framework.TestCase.runBare(TestCase.java:127)
    	at junit.framework.TestResult$1.protect(TestResult.java:106)
    	at junit.framework.TestResult.runProtected(TestResult.java:124)
    	at junit.framework.TestResult.run(TestResult.java:109)
    	at junit.framework.TestCase.run(TestCase.java:118)
    	at junit.framework.TestSuite.runTest(TestSuite.java:208)
    	at junit.framework.TestSuite.run(TestSuite.java:203)
    	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    Voici mon fichier hibernate.cfg.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
     
    <hibernate-configuration>
    	<session-factory>
    		<property name="hibernate.connection.url">jdbc:bea:oracle://xxx:1521:XXX</property>
    		<property name="hibernate.connection.driver_class">weblogic.jdbc.oracle.OracleDriver</property>
    		<property name="hibernate.connection.username">xxx</property>
    		<property name="hibernate.connection.password">xxx</property>
     
     
    		<property name="transaction.manager_lookup_class">
    			org.hibernate.transaction.WeblogicTransactionManagerLookup
    		</property>
    		<property name="dialect">org.hibernate.dialect.OracleDialect</property>
    		<property name="current_session_context_class">thread</property>
    		<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
    		<property name="hibernate.show_sql">false</property>
     
    		[...]
    	</session-factory>
    </hibernate-configuration>
    Il semblerait en fait que mon fichier hibernate.cfg.xml n'est pas pris en compte que je tombe sur la même exception même si le fichier hibernate est absent.

  2. #2
    Expert éminent sénior
    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 : 45
    Localisation : Belgique

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

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Points : 48 807
    Points
    48 807
    Par défaut
    ou est placé ce fichier de configuration, comme le prend-tu en compte? Comment initialise-tu hibernate?

  3. #3
    Membre éclairé
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    802
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 802
    Points : 653
    Points
    653
    Par défaut
    Pour le chargement du fichier hibernate, lorsque je suis en standalone, le chemin est en dur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    public static void initSessionFactory() {
            String propertiesPath = "P:\\xxx\\properties";
            File fileConfiguration = new File(propertiesPath + "hibernate.cfg.xml");
            sessionFactory = new Configuration().configure(fileConfiguration).buildSessionFactory();
    }
    J'appelle cette méthode initSessionFactory() dans le constructeur de mon test JUnit, et c'est là que j'ai une exception.

Discussions similaires

  1. Tomcat 6, Bonita "Could not find datasource"
    Par jefquebec dans le forum Tomcat et TomEE
    Réponses: 0
    Dernier message: 05/04/2012, 14h51
  2. Could not find datasource [WASCE]
    Par libuma dans le forum Hibernate
    Réponses: 2
    Dernier message: 25/03/2011, 08h38
  3. [jBPM] JobExecutorThread : Could not find datasource
    Par Jacques - 06 dans le forum Wildfly/JBoss
    Réponses: 1
    Dernier message: 21/08/2007, 14h28
  4. [Hibernate] : Erreur Could not find datasource
    Par tipaquo dans le forum Hibernate
    Réponses: 2
    Dernier message: 12/10/2005, 10h43
  5. Réponses: 3
    Dernier message: 30/03/2005, 23h15

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