jboss5.1+spring+jpa [ No unique bean of type [javax.persistence.EntityManagerFactory] is defined]
Define oracle-ds.xml
<local-tx-datasource> <jndi-name>timekerOracleDS</jndi-name> .... </local-tx-datasource>
Define persistence.xml
<persistence-unit name="timeker" transaction-type="JTA"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:timekerOracleDS</jta-data-source> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect"/> <property name="hibernate.hbm2ddl.auto" value="update"/> <property name="hibernate.show_sql" value="true"/> <property name="hibernate.format_sql" value="true"/> <property name="jboss.entity.manager.factory.jndi.name" value="java:/timeker"/> </properties> </persistence-unit>
Define spring
applicationContext.xml
<aop:aspectj-autoproxy /> <context:annotation-config /> <context:component-scan base-package="com.paokuang"/> <jee:jndi-lookup id="entityManagerFactory" jndi-name="java:/timeker"/> <bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="transactionManagerName" value="java:/TransactionManager"/> <property name="userTransactionName" value="UserTransaction"/> </bean> <tx:annotation-driven transaction-manager="txManager"/>
Define the Spring configuration file in the
web.xml
file<persistence-unit-ref> <persistence-unit-ref-name>persistence/timeker</persistence-unit-ref-name> <persistence-unit-name>timeker</persistence-unit-name> </persistence-unit-ref>
but when I deployed the war into jboss,occured the error:
Error creating bean with name 'productTypeServiceBean': Injection of persistence fields failed; n开发者_开发百科ested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [javax.persistence.EntityManagerFactory] is defined: expected single bean but found 0
How to resolve the problem or tell the right configuration spring+jpa+jboss?
You are missing the EntityManagerFactory
bean in your applicationContext.xml
.
Probably the easiest way is to configure the LocalContainerEntityManagerFactoryBean
:
<bean id="myEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="someDataSource"/>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
</property>
</bean>
See http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/orm.html for more details.
精彩评论