[SPRING][STRUTS2][JPA]NoSuchBeanDefinitionException avec JPA et Struts2
Bonjour,
Je suis en train de développer 1 webapp utilisant Struts2 et cette webapp est buildée en utilisant Maven.
J'ai un petit problème avec spring.
Voici une explication du problème :
Mon projet maven pour ma webapp possède une dépendance avec mon projet "DAO" qui utilise lui aussi pring. Au niveau DAO, tout le configuration de JPA est effectuée dans Spring à l'exception de la datasource qui elle est définie dans la web app (comme ça je peux avoir 1 datasource pour le test qui utilise HSQL DB et une autre pour la webapp qui utilise postgresql).
Mais quand j'exécute je reçois l'exception suivante :
Code:
1 2 3 4 5 6 7 8 9 10 11
| org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' is defined
org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:353)
org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:916)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:243)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:737)
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.lookupEntityManagerFactory(OpenEntityManagerInViewFilter.java:150)
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.lookupEntityManagerFactory(OpenEntityManagerInViewFilter.java:133)
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:92)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96) |
Voici le conteu de mon fichier applicationContext.xml au niveau du projet DAO :
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
| <?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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<!-- ******************************************************************************************************** -->
<!-- ** Our DAOs ** -->
<!-- ******************************************************************************************************** -->
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="groupDao" class="kicker.dao.springhibernate.GroupDaoImpl" />
<bean id="daoFacade" class="kicker.dao.DaoFacade">
<property name="groupDao">
<ref local="groupDao" />
</property>
</bean>
<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="database" value="POSTGRESQL" />
<property name="showSql" value="true" />
</bean>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- ******************************************************************************************************** -->
<!-- ** AOP Features (exceptions, logging, ...) ** -->
<!-- ******************************************************************************************************** -->
<!-- DAO interceptor -->
<bean id="dataAccessInterceptor" class="kicker.aop.DataAccessThrowsAdvice" />
<bean id="daoAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="pattern">
<value>.*dao.*</value>
</property>
<property name="advice">
<ref local="dataAccessInterceptor"/>
</property>
</bean>
</beans> |
Voici maintenant la définition du fichier applicationContext au niveau du projet WEB :
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
| <?xml version="1.0" encoding="UTF-8"?>
<!--
CVS file status:
$Id: testDaoApplicationContext.xml,v 1.11 2007/07/12 08:10:09 fv Exp $
Copyright (c) SmalS-MvM
-->
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- ******************************************************************************************************** -->
<!-- ** AOP Features (exceptions, logging, ...) ** -->
<!-- ** - used to create proxies for Advisor/Advice defined in applicationContext.xml ** -->
<!-- ******************************************************************************************************** -->
<bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" />
<!-- ******************************************************************************************************** -->
<!-- ** DataSources definitions ** -->
<!-- ** - dataSource ==> direct connection to in-memory HSQL Database ** -->
<!-- ******************************************************************************************************** -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName"><value>org.postgresql.Driver</value></property>
<property name="url"><value>jdbc:postgresql://localhost:5432/kicker</value></property>
<property name="username"><value>kicker</value></property>
<property name="password"><value>kicker</value></property>
</bean>
</beans> |
Voici finalement le fichier web.xml de ma webapp :
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
| <?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Kicker Struts 2 WebAPP</display-name>
<filter>
<filter-name>SpringOpenEntityManagerInViewFilter</filter-name>
<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
</filter>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>SpringOpenEntityManagerInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app> |
Pourriez-vous me dire comment je peux éliminer l'exception (tout en gardant 2 projets bien séparés) ?
Petite information : je tiens absolument à utiliser spring dans les 2 projets mais apparemment le fichier applicationContext.xml qui est situer dans le JAR du projet DAO n'est pas charger.
Merci d'avance pour votre aide.
hubeaul