1

I have an EJB that's annotated as follows:

@Stateless
@Interceptors(SpringBeanAutowiringInterceptor.class)

The SpringBeanAutowiringInterceptor creates a ClassPathXmlApplicationContext which in turn creates some @Components. One of these @Components is a DAO and thus likes to get an EntityManager injected. Preferably this should be the EJB's container-managed EntityManager (as per my current insights).

If I add to the EJB the following, that works just fine:

@PersistenceContext
EntityManager entityManager;

If I however do the latter on my DAO (which is in Spring which is its own context) that does not work. Regardless of whether I call out the unit name specifically or not (unitName="test", "No bean named 'test' is defined" versus "No unique bean of type [javax.persistence.EntityManagerFactory]").

I've tried jee:jndi-lookup in Spring, but I'm at a loss of how to make the entity manager available in JNDI for that to work. Should that be somehow done in my persistence.xml or even at another level?

I'm running all this in JBOSS as an Arquillian test, but my target environment is WAS. I should thus also steer away from container-specific solutions. This is not a WAR project, rather shrinkwrapping the EJB JAR in an EAR.

I think I'm looking for the general concept or the best practice here, to move me forward. (Hence I limited the amount of code included in the question, though I'm happy to share some specifics if that'd help.) Thanks!

Sander Verhagen
  • 8,540
  • 4
  • 41
  • 63

1 Answers1

0

add the following to your Spring Config

<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
fpmoles
  • 1,209
  • 8
  • 14