I am trying to use Spring to inject @PersistenceContext entityManager into my service. The following configuration works autonomously, but does not work when deployed to Tomcat. When deployed to Tomcat, the entityManager remains null. My JPA configurations are in persistence.xml.
<context:annotation-config /> <tx:annotation-driven/> <bean id="entityManagerFactory" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> <property name="staticMethod"> <value>javax.persistence.Persistence.createEntityManagerFactory</value> </property> <property name="arguments"> <list> <value>persistenceUnit</value> </list> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory"/> </bean>
What configuration changes do I need to make for injection to work with Tomcat 6 vs standalone?
Edit: I can get the factory inside the service and get entityManager from it, so the persistence.xml parameters seem to work correctly.
Solution: I turned on the Spring log to find the problem - the missing library. Spring seems to fail if the above transactionManager bean cannot be created.
source share