2013-04-24 34 views
1

我有如下注的一个EJB:的EntityManager中的SpringBeanAutowiringInterceptor创建上下文

@Stateless 
@Interceptors(SpringBeanAutowiringInterceptor.class) 

SpringBeanAutowiringInterceptor创建ClassPathXmlApplicationContext这反过来又创造了一些@Component秒。其中一个@Component s是DAO,因此喜欢注入EntityManager。最好这应该是EJB的容器管理的EntityManager(根据我目前的见解)。

如果我添加到EJB以下,将工作得很好:

@PersistenceContext 
EntityManager entityManager; 

如果然而,我做我的DAO(这是在春天这是它自己的上下文),后者不起作用。不管我是否具体说出单位名称(unitName="test",“No bean named 'test' is defined”与“No unique bean of type [javax.persistence.EntityManagerFactory]”)。

我在Spring中尝试过jee:jndi-lookup,但是我在如何使JNDI中的实体管理器可用以使其工作方面遇到困难。这应该在我的persistence.xml或甚至在另一个层面做到?

作为Arquillian测试,我在JBOSS中运行所有这些,但我的目标环境是WAS。因此,我也应该避开容器特定的解决方案。这不是一个WAR项目,而是将EJB JAR包装在一个EAR中。

我想我正在寻找这里的一般概念或最佳实践,以推动我前进。 (因此,我限制了包含在问题中的代码量,尽管如果有帮助,我很乐意分享一些细节。)谢谢!

+0

看看这个:http://stackoverflow.com/a/4717196/1850609 – acdcjunior 2013-04-26 02:23:23

+0

大问题。 – Ceki 2014-02-05 14:38:00

回答

0

以下内容添加到您的Spring配置

<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />