Bonjour,

Je suis en train de créer un environnement de test avec JUnit et glassfish. J'ai une base de données de tests avec deux fichiers de configuration : l'un permet contient les info de config pour Hibernate (rmptoolTests.hibernate.cfg.xml) et l'autre contient les infos sur mes DAO (daoBeansTests.xml).

Le problème vient quand je veux charger le contexte pour pouvoir accéder à mes DAO et à mes services. j'obtiens l'exception suivante :

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
53
54
55
56
57
58
 
17-05 10:11:35,472 - INFO  [support.AbstractApplicationContext] (AbstractApplicationContext.java:411) - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1c1ea29: display name [org.springframework.context.support.ClassPathXmlApplicationContext@1c1ea29]; startup date [Mon May 17 10:11:35 CEST 2010]; root of context hierarchy
17-05 10:11:35,534 - INFO  [xml.XmlBeanDefinitionReader] (XmlBeanDefinitionReader.java:323) - Loading XML bean definitions from class path resource [daoBeansTests.xml]
17-05 10:11:35,691 - INFO  [support.AbstractApplicationContext] (AbstractApplicationContext.java:426) - Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@1c1ea29]: org.springframework.beans.factory.support.DefaultListableBeanFactory@90cb03
17-05 10:11:35,769 - INFO  [support.DefaultListableBeanFactory] (DefaultListableBeanFactory.java:414) - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@90cb03: defining beans [mySessionFactory,transactionManager,transactionAdvice,org.springframework.aop.config.internalAutoProxyCreator,transactionPointcut,org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0,daoAction,mgrAction,daoActionHistory,mgrActionHistory,daoActor,mgrActor,daoGroup,mgrGroup,daoOperation,mgrOperation,daoRisk,mgrRisk,daoRiskHistory,mgrRiskHistory,daoType,mgrType,daoLdapUser,mgrLdapUser]; root of factory hierarchy
17-05 10:11:35,956 - INFO  [support.DefaultSingletonBeanRegistry] (DefaultSingletonBeanRegistry.java:421) - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@90cb03: defining beans [mySessionFactory,transactionManager,transactionAdvice,org.springframework.aop.config.internalAutoProxyCreator,transactionPointcut,org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0,daoAction,mgrAction,daoActionHistory,mgrActionHistory,daoActor,mgrActor,daoGroup,mgrGroup,daoOperation,mgrOperation,daoRisk,mgrRisk,daoRiskHistory,mgrRiskHistory,daoType,mgrType,daoLdapUser,mgrLdapUser]; root of factory hierarchy
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in class path resource [daoBeansTests.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingNotFoundException: resource: mapping/Action.hbm.xml not found
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
	at tests.com.infotel.RMPTool.action.json.export.ExportFeuilleActionTest.initialiser(ExportFeuilleActionTest.java:57)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
	at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
	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)
Caused by: org.hibernate.MappingNotFoundException: resource: mapping/Action.hbm.xml not found
	at org.hibernate.cfg.Configuration.addResource(Configuration.java:563)
	at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1587)
	at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)
	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)
	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
	at org.hibernate.cfg.Configuration.configure(Configuration.java:1443)
	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:601)
	at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
	... 38 more
Ce qui est bizarre c'est que j'ai mes fichier de mapping dans un package du même répertoire que ces fichiers de config.

voilà le fichier rmptoolTests.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
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
		"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
		"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
	<session-factory>
 
		<!-- Database connection settings -->
 
		<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
 
		<property name="connection.datasource">RMPToolTestsUnitaires</property>
 
		<!-- SQL dialect -->
		<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
 
		<!-- Disable the second-level cache -->
		<property name="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
 
		<!-- Echo all executed SQL to stdout -->
		<property name="hibernate.show_sql">false</property>
		<property name="hibernate.format_sql">false</property>
 
		<!-- Mapping files -->
		<mapping resource="mapping/Action.hbm.xml" />
        <mapping resource="mapping/ActionHistory.hbm.xml" />
       	<mapping resource="mapping/Actor.hbm.xml" />
       	<mapping resource="mapping/Group.hbm.xml" />
       	<mapping resource="mapping/Operation.hbm.xml" />
       	<mapping resource="mapping/Risk.hbm.xml" />
       	<mapping resource="mapping/RiskHistory.hbm.xml" />
       	<mapping resource="mapping/Type.hbm.xml" />
       	<mapping resource="mapping/LdapUser.hbm.xml" />
 
	</session-factory>
</hibernate-configuration>
voilà le fichier rmptoolTests.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
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
60
61
62
63
64
65
66
<?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:aop="http://www.springframework.org/schema/aop"
		xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
		xmlns:jee="http://www.springframework.org/schema/jee" 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-2.5.xsd
			http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
			http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
			http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
 
 
	<bean id="mySessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="configLocation">
			<value>./rmptoolTests.hibernate.cfg.xml</value>
		</property>
	</bean>
 
 
	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" 
		p:sessionFactory-ref="mySessionFactory" />
 
	<!-- <tx:annotation-driven transaction-manager="transactionManager"/> -->
 
	<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
		<!-- the transactional semantics... -->
		<tx:attributes>
			<!-- all methods starting with 'get' are read-only -->
			<tx:method name="get*" read-only="true" rollback-for="com.infotel.framework.manager.exception.ManagerException" />
			<tx:method name="set*" read-only="true" rollback-for="com.infotel.framework.manager.exception.ManagerException" />
			<tx:method name="load*" read-only="true" rollback-for="com.infotel.framework.manager.exception.ManagerException" />
			<!-- other methods use the default transaction settings (see below) -->
			<tx:method name="*" rollback-for="com.infotel.framework.manager.exception.ManagerException" />
		</tx:attributes>
	</tx:advice>
 
 
	<!--
		ensure that the above transactional advice runs for any execution of
		Manager
	-->
	<aop:config>
		<aop:pointcut id="transactionPointcut" expression="execution(public * com.infotel.RMPTool.manager..*.*(..)) || execution(public * com.infotel.framework.manager..*.*(..))" />
		<aop:advisor advice-ref="transactionAdvice" pointcut-ref="transactionPointcut" />
	</aop:config>
 
	<!-- DAO and Manager Declarations -->
	<!-- Actions -->
	<bean id="daoAction"
		class="com.infotel.RMPTool.dao.ActionDAO">
		<property name="className">
			<value>com.infotel.RMPTool.bean.Action</value>
		</property>
	</bean>
	<bean id="mgrAction"
		class="com.infotel.RMPTool.manager.ActionManager">
		<property name="dao">
			<ref bean="daoAction" />
		</property>
	</bean>
 
...
 
</beans>
En vous remerciant,
Nicolas