Why Spring doesn't insert @PersistenceContext entityManager when running on Tomcat vs standalone

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.

+4
source share
1 answer

If I understand correctly, you should make sure that persistence.xml exists in the correct path on your tomato or more precisely in your class path.
At least I had such problems when working with a corporate application, so I think this is a good place to start looking for an answer.
Have you checked the magazines? Do they have anything interesting?

+3
source

All Articles