Hi,
I am working with JBoss 4.2.3, springframework 2.5, and Hibernate for my web app. I am trying to bind the persistence unit configured in the persistence.xml to jndi but to no avail. Could somebody shed some light on me about the right approach? Thanks.
Here is my configuration and stack trace. I could not find the MyAppPU under the jndi view.
web.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>********</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<persistence-unit-ref>
<description> Persistence unit for the application. </description>
<persistence-unit-ref-name>persistence/MyAppPU</persistence-unit-ref-name>
<persistence-unit-name>MyAppPU</persistence-unit-name>
</persistence-unit-ref>
<jsp-config>
<taglib>
<taglib-uri>/spring</taglib-uri>
<taglib-location>
/WEB-INF/tld/spring-form.tld
</taglib-location>
</taglib>
</jsp-config>
</web-app>
applicationContext.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:seam="http://jboss.com/products/seam/spring-seam"
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:jee="http://www.springframework.org/schema/jee"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://jboss.com/products/seam/spring-seam
http://jboss.com/products/seam/spring-seam-2.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.5.xsd">
<!-- <seam:configure-scopes default-auto-create="true" /> -->
<context:annotation-config />
<context:component-scan
base-package="************">
</context:component-scan>
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<bean
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
</bean>
<jee:jndi-lookup id="entityManagerFactory" jndi-name="java:/MyAppPU"/>
<bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor">
</bean>
<jee:jndi-lookup id="dataSource" jndi-name="**********" />
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
</bean>
<tx:jta-transaction-manager />
<tx:annotation-driven transaction-manager="txManager" />
<!-- Let's access the JTA transaction manager of the application server -->
<bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManagerName" value="java:/TransactionManager"/>
<property name="userTransactionName" value="UserTransaction"/>
</bean>
<!-- TaskExecutor for example use of @Asynchronous -->
<bean id="springThreadPoolTaskExecutor"
class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor" />
<aop:config>
<aop:advisor pointcut="execution(* *..*******.*(..))"
advice-ref="txAdvice" />
</aop:config>
<tx:advice id="txAdvice">
<tx:attributes>
<tx:method name="save*" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
</beans>
persistence.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" 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">
<persistence-unit name="MyAppPU" transaction-type="JTA" >
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:MyDS</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.cache.use_second_level_cache" value="false" />
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
<property name="hibernate.transaction.flush_before_completion" value = "true"/>
<property name="jboss.entity.manager.jndi.name" value="java:/MyAppEM"/>
<property name="jboss.entity.manager.factory.jndi.name" value="java:/MyAppPU"/>
</properties>
</persistence-unit>
</persistence>
stack trace:
Code:
08:25:43,010 INFO [0]] Initializing Spring root WebApplicationContext
08:25:43,010 INFO [ContextLoader] Root WebApplicationContext: initialization started
08:25:43,119 INFO [XmlWebApplicationContext] Refreshing org.springframework.web.context.support.Xml
WebApplicationContext@16a93b8: display name [Root WebApplicationContext]; startup date [Mon Aug 17 0
8:25:43 EDT 2009]; root of context hierarchy
08:25:43,353 INFO [XmlBeanDefinitionReader] Loading XML bean definitions from ServletContext resour
ce [/WEB-INF/applicationContext.xml]
08:25:44,072 INFO [XmlWebApplicationContext] Bean factory for application context [org.springframew
ork.web.context.support.XmlWebApplicationContext@16a93b8]: org.springframework.beans.factory.support
.DefaultListableBeanFactory@121784f
08:25:45,182 INFO [JtaTransactionManager] Using JTA UserTransaction: org.jboss.tm.usertx.client.Ser
verVMClientUserTransaction@90a278
08:25:45,182 INFO [JtaTransactionManager] Using JTA TransactionManager: com.arjuna.ats.jbossatx.jta
.TransactionManagerDelegate@19a82ee
08:25:46,713 ERROR [ContextLoader] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataHandler'
defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to b
ean 'dataRepository' while setting bean property 'dataRepository'; nested exception is org.springfra
mework.beans.factory.BeanCreationException: Error creating bean with name 'dataRepository': Injectio
n of persistence fields failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefi
nitionException: No unique bean of type [javax.persistence.EntityManagerFactory] is defined: expecte
d single bean but found 0
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with nam
e 'entityManagerFactory': Invocation of init method failed; nested exception is javax.naming.NameNot
FoundException: MyAppPU not bound
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with nam
e 'entityManagerFactory': Invocation of init method failed; nested exception is javax.naming.NameNot
FoundException: MyAppPU not bound
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefin
itionValueResolver.java:275)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(Be
anDefinitionValueResolver.java:104)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues
(AbstractAutowireCapableBeanFactory.java:1244)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(Abstra
ctAutowireCapableBeanFactory.java:1008)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(Abstra
ctAutowireCapableBeanFactory.java:470)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutow
ireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(Abstract
AutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.ja
va:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingl
etonBeanRegistry.java:217)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java
:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:1
85)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:1
64)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateS