带有EJB3.0和websphere6.1的无状态会话bean的问题

时间:2012-04-09 20:12:46

标签: session ejb-3.0 javabeans stateless

**我无法使用EJB3.0和Websphere 6.1创建无状态会话bean。

我将所有内容打包到EAR文件中并将其部署在Websphere上。 我正在尝试创建一个无状态会话bean并期望它实例化会话bean并调用ejbCreate()。**

Following is my code and xml file.

package com.aa.otrs.datacollector.reject.ejb;

import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.ejb.Timeout;
import javax.ejb.Timer;
import javax.ejb.TimerService;
import javax.interceptor.Interceptors;
import com.aa.otrs.datacollector.logging.DataCollectorLogger;
import com.aa.otrs.fraudnet.service.FraudNetSoapWrapperService;
import com.google.inject.Inject;

@Stateless
@Interceptors(GuiceInterceptor.class)
public class RejectServiceBean implements IRejectServiceBean{

     @Inject
     private DataCollectorLogger logger;
     @SuppressWarnings("unused")
     @Inject
            private FraudNetSoapWrapperService fraudnetWebService;
     @Resource
     private TimerService timerService;

     public void ejbCreate() throws javax.ejb.CreateException {
         logger.debug("On ejbCreate");
         logger.debug(“RejectServiceBean ");

     }

     public void ejbActivate() {
         logger.debug("ejbActivate");
     }

}

This is ibm-ejb-jar-bnd xml file under META-INF folder.

<ejb-jar-bnd xmlns="http://websphere.ibm.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee     http://websphere.ibm.com/xml/ns/javaee/ibm-ejb-jar-bnd_1_0.xsd"
    version="1.0">
    <message-driven name="PnrMessageBean">
        <listener-port name="RECLOCATOR.LP" />
    </message-driven>

    <session name="RejectServiceBean">
    <interface class="com.aa.otrs.datacollector.reject.ejb.IRejectServiceBean" 
                binding-name="ejblocal:ejb/RejectServiceBean"/>
    </session>

</ejb-jar-bnd>

import javax.ejb.Local;

@Local
public interface IRejectServiceBean {

    void callingInterface();
}

I have tried implementing stateless session with or without interface and xml file. 

import com.google.inject.Inject;
import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.ejb.TimedObject;
import javax.ejb.Timeout;
import javax.ejb.Timer;
import javax.ejb.TimerService;
import javax.interceptor.Interceptors;
import com.aa.otrs.datacollector.logging.DataCollectorLogger;
import com.aa.otrs.fraudnet.service.FraudNetSoapWrapperService;


@Stateless
@Interceptors(GuiceInterceptor.class)
public class RejectServiceSessionBean {
     @Inject
     private DataCollectorLogger logger;
     @Inject
     private FraudNetSoapWrapperService fraudnetWebService;


     public void ejbCreate() throws javax.ejb.CreateException {
         logger.debug("On ejbCreate");
         logger.debug("In RejectServiceSessionBean constructor");

     }
     public void ejbActivate() {
         logger.debug("ejbActivate");
     }


public class GuiceInterceptor{
       private static final Injector injector = Guice.createInjector(new EjbEnvironmentModule());

       @PostConstruct
       @PostActivate
       public void autowireBean(InvocationContext invocationContext) {
           Object target = invocationContext.getTarget();
           injector.injectMembers(target);
       }


    }

问题:从上面两个代码片段开始,它永远不会调用ejbCreate或ejbActivate方法。 我已经放置了记录器,以便我可以验证它是否通过这些方法。

1 个答案:

答案 0 :(得分:0)

对于EJB-3.0无状态bean,您可以使用@PostConstruct&amp ;;来生成生命周期回调方法。 @PreDestroy注释。

这些方法必须公开,返回void&amp;没有任何参数。