在具有SpringBeanAuthoringInterceptor的EJB中未找到SpringBean

在具有SpringBeanAuthoringInterceptor的EJB中未找到SpringBean,spring,ejb,autowired,interceptor,Spring,Ejb,Autowired,Interceptor,我需要一些帮助:我有一个EAR文件,其中包含一个WAR文件、一个EJB Jar文件和一些“共享”LIB: War文件有一个上下文初始值设定项,可以找到spring配置并很好地加载所有内容。 现在我想为ejbjar使用另一个Spring上下文。 我的EJB定义为 @Stateless(mappedName = "ejb/SpringRocks") @RemoteHome(com.ibm.websphere.ola.ExecuteHome.class) @Interceptors(SpringBea

我需要一些帮助:我有一个EAR文件,其中包含一个WAR文件、一个EJB Jar文件和一些“共享”LIB:

War文件有一个上下文初始值设定项,可以找到spring配置并很好地加载所有内容。 现在我想为ejbjar使用另一个Spring上下文。 我的EJB定义为

@Stateless(mappedName = "ejb/SpringRocks")
@RemoteHome(com.ibm.websphere.ola.ExecuteHome.class)
@Interceptors(SpringBeanAutowiringInterceptor.class)
public class WolaUseCaseOne {
  @Autowired
  private DummyService dummyService;
  /* ...More stuff here */
在EJB-JAR中,还有一个beanRefContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd">
  <bean id="myEjb" name="myEjb" class="org.springframework.context.support.ClassPathXmlApplicationContext">
   <constructor-arg value="classpath*:META-INF/spring/simpleEjb.xml" />
  </bean>
</beans>

simpleEjb.xml也在EJB Jar中,它定义了一个非常简单的Bean:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
  <bean id="myDummyService" class="com.provinzial.beispielanwendung.batch.wola.DummyServiceImpl" />
</beans>

如前所述,WEB部件工作正常,但是当调用EJB时,SpringBeanAutowiringInterceptor被调用,但似乎什么也不做。要创建一个Spring上下文,我必须做什么?!我希望在创建EJB时初始化它。我用一些记录器创建了SpringBeanAutowiringInterceptor的一个子类,但是只创建了这个类,没有调用任何方法! 我还需要做什么?或者有人有有效的EAR文件示例吗? 我认为问题在于EJB模块内部没有初始化上下文

问候
Timo

我的EJB也面临着类似的问题(没有战争)。这就是我的

  • 我错过了类路径上的spring aop jar。我看你那里的味道很好
  • 在我的ejb-jar.xml文件中,我将元数据标志设置为true,这样就不会在部署完成时收到提示

  • 对于一个部署,我将其设置为“false”,以查看IBM为我生成了什么。在ejb-jar.xml中添加了以下内容(我的MDB名为TaskMDB)

    
    TaskMDB
    org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor
    org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor
    org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor
    蚕豆
    org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor
    释放豆
    org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor
    蚕豆
    org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor
    释放豆
    
    然后,我将IBM生成的内容(汇编描述符和拦截器节)添加回ejb-jar.xml,并将元数据complete设置回true

    然后它成功了。希望这有帮助

    下面是完整的ejb-jar.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <ejb-jar version="3.1" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd">
        <display-name>ares-api-uow-ejb</display-name>
        <enterprise-beans>
            <message-driven id="TaskMDB">
                <ejb-name>TaskMDB</ejb-name>
                <ejb-class>something.api.uow.ejb.mdb.TaskMDB</ejb-class>
                <messaging-type>javax.jms.MessageListener</messaging-type>
                <transaction-type>Bean</transaction-type>
            </message-driven>
        </enterprise-beans>
    </ejb-jar>
    
    
    ares api uow ejb
    TaskMDB
    something.api.uow.ejb.mdb.TaskMDB
    javax.jms.MessageListener
    豆子
    
    Hi Bulldogs,感谢您的回复。。。我根本不使用ejb-jar.xml,只是简单的注释。你能把完整的ejb-jar.xml发给我吗?
    <assembly-descriptor>
            <interceptor-binding>
                <ejb-name>TaskMDB</ejb-name>
                <interceptor-class>org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor</interceptor-class>
            </interceptor-binding>
        </assembly-descriptor>
    
        <interceptors>
            <interceptor>
                <interceptor-class>org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor</interceptor-class>
                <post-activate>
                    <lifecycle-callback-class>org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor</lifecycle-callback-class>
                    <lifecycle-callback-method>autowireBean</lifecycle-callback-method>
                </post-activate>
                <pre-passivate>
                    <lifecycle-callback-class>org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor</lifecycle-callback-class>
                    <lifecycle-callback-method>releaseBean</lifecycle-callback-method>
                </pre-passivate>
                <post-construct>
                    <lifecycle-callback-class>org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor</lifecycle-callback-class>
                    <lifecycle-callback-method>autowireBean</lifecycle-callback-method>
                </post-construct>
                <pre-destroy>
                    <lifecycle-callback-class>org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor</lifecycle-callback-class>
                    <lifecycle-callback-method>releaseBean</lifecycle-callback-method>
                </pre-destroy>
            </interceptor>
        </interceptors>
    
    <?xml version="1.0" encoding="UTF-8"?>
    <ejb-jar version="3.1" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd">
        <display-name>ares-api-uow-ejb</display-name>
        <enterprise-beans>
            <message-driven id="TaskMDB">
                <ejb-name>TaskMDB</ejb-name>
                <ejb-class>something.api.uow.ejb.mdb.TaskMDB</ejb-class>
                <messaging-type>javax.jms.MessageListener</messaging-type>
                <transaction-type>Bean</transaction-type>
            </message-driven>
        </enterprise-beans>
    </ejb-jar>