Fichier persistence.xml non reconnu
Bonjour à tous : )
Je vous expose un petit problème bien embêtant, à force de parcourir des tutoriel, etc et ne pas en trouvé de réponse.
J'ai une application serveur Spring 3 - Ejb3 - Jpa - Hibernate - mysql - tomcat
J'ai configuré le context de spring mais celui-ci me retourne une erreur, lors de la recherche de mon fichier de persistence.
Code:
1 2 3
|
GRAVE: 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 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0' defined in ServletContext resource [/WEB-INF/classes/webApplicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/classes/webApplicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: No persistence unit with name 'jpaVille' found |
Voici mon context spring - Référence : bean "entityManager"
Code:
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
<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:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
<!-- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd" -->
<!-- ************ SERVICE *********** -->
<!-- La Transaction -->
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:advice id="serviceTxAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="find*" propagation="REQUIRED" read-only="true" />
<tx:method name="*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="serviceMethods" expression="execution(* service.nasch.*.*(..))" />
<aop:advisor advice-ref="serviceTxAdvice" pointcut-ref="serviceMethods" />
</aop:config>
<!-- Configuration de proxy spécifiques, héritant du proxy général, devant chaque bean potentiellement transactionnel -->
<!-- ***********************
** Beans Service **
************************ -->
<bean id="ServiceContinentGeonamesTarget" class="service.nasch.ville.ServiceContinentGeonames">
<property name="continentDao" ref="continentDao"/>
</bean>
<bean id="ServiceContinentGeonames" parent="transactionProxy">
<property name="target">
<ref bean="ServiceContinentGeonamesTarget"/>
</property>
<property name="transactionAttributeSource">
<bean class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"/>
</property>
</bean>
<!-- ************ MODELE ************** -->
<!-- ***************************
** TransactionManager **
***************************** -->
<!-- Gestions des Transactions BDD -->
<!-- Définition du proxy général abstrait de manière globale à lapplication -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<!-- ****************************
** TransactionProxy **
***************************** -->
<bean id="transactionProxy" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED, readOnly</prop>
</props>
</property>
</bean>
<!-- ***********************
** BDD DataSource **
************************ -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/madb</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>mdp</value>
</property>
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="persistenceUnitName" value="jpaVille"/>
<property name="jpaVendorAdapter">
<bean
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="generateDdl" value="true" />
<property name="showSql" value="true" />
<property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
</bean>
</property>
</bean>
<!-- ***********************
** JBDC Exception **
************************ -->
<bean id="jdbcExceptionTranslator" class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator ">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
</bean>
<!-- ***********************
** Beans DAO **
************************ -->
<!-- General -->
<bean id="continentDao" class="dao.nasch.ville.impl.ContinentGeonamesHome">
<property name="entityManagerFactory">
<ref bean="entityManagerFactory"/>
</property>
</bean>
<!-- *********** BEAN FOR TEST *************** -->
<bean id="welcomeServiceBean" class="com.nasch.welcomeService.WelcomeService"/>
<!-- *********** CLASS ************ -->
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
<!-- ************* PACKAGE ******************* -->
<!-- tell spring to use annotation based congfigurations -->
<context:annotation-config/>
<!-- tell spring where to find the beans -->
<context:component-scan base-package="dao.nasch.ville.impl" />
<tx:annotation-driven/>
<tx:jta-transaction-manager/>
</beans> |
Mon fichier "persistence.xml" situé dans "META-INF"
Code:
1 2 3 4 5 6 7 8 9 10 11
|
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="jpaVille" transaction-type="JTA">
<class>dao.nasch.ville.impl.ContinentGeonamesHome</class>
</persistence-unit>
</persistence> |
la classe ContinentGeonames (pour donner une idée), car là je n'intitule le nom de référence de la persistence "jpaVille" en parametre de mon context "EntityManager" vu que je veux qu'il soit fait par Spring (je trouve que c'est mieux comme ça)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
public class ContinentGeonamesHome {
private static final Log log = LogFactory
.getLog(ContinentGeonamesHome.class);
/* PAS comme ça => @PersistenceContext(unitName="jpaVille")
private EntityManager em; */
@PersistenceContext
private EntityManager entityManager;
public void persist(ContinentGeonames transientInstance) {
log.debug("persisting ContinentGeonames instance");
try {
entityManager.persist(transientInstance);
log.debug("persist successful");
} catch (RuntimeException re) {
log.error("persist failed", re);
throw re;
}
} |
Je ne vois pas pourquoi il n'est donc trouvé !!
Entre des pb de classpath vu ailleurs (ayant donc ajouté caché au java build path le dossier "Meta-Inf")
ou alors ajouté un jdni (mui bon, pas trop compris cette méthode, ça devrait marcher comme ça normalement),
renommer le fichier (étrange, je pensais que c'était normalisé),
ou même donner le nom du fichier et non celui de "persistence_unit".
Mon classe path :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
|
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="WebContent/META-INF"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.6.0_14"/>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v6.0"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
.....
.....
<classpathentry kind="output" path="WebContent/WEB-INF/classes"/>
</classpath> |
Je ne vois pas comment y résoudre.
ps : si j'utilise la version :
Code:
1 2 3
|
@PersistenceContext(unitName="jpaVille")
private EntityManager entityManager; |
j'ai une erreur :
Code:
1 2
|
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0' defined in ServletContext resource [/WEB-INF/classes/webApplicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/classes/webApplicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: No persistence units parsed from {classpath*:META-INF/persistence.xml} |