**我无法使用 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 方法。我已经放置了记录器,以便我可以验证它是否通过这些方法。