2012-04-09 53 views
0

**我無法使用EJB3.0和Websphere 6.1創建無狀態會話Bean。使用EJB3.0和websphere6.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方法調用。 我已經把日誌記錄器,以便我可以驗證它是否通過這些方法。

回答

0

對於EJB-3.0無狀態bean,可以通過使用@PostConstruct & @PreDestroy註釋來實現生命週期回調方法。

這些方法必須是公開的,返回void &沒有任何參數。