mercredi 28 mai 2014

Java - déployer EJB 3 projet séparé et accès par le biais de la servlet dans Websphere 7 - Stack Overflow


I have created sample EJB 3 application with annotation in WebSphere 7. It is like this.



  1. The local interface

    @Local
    public interface ICalLocalBean{

    public int add(int a, int b);

    }

  2. Implementation of EJB.

    @Stateless
    public class CalcEJBean implements ICalLocalBean {

    @Override
    public int add(int a, int b) {
    return a + b;
    }

    }

  3. Access the EJB inside the servlet.

    public class CalcServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    @EJB
    private ICalLocalBean iCalLocalBean;

    ...

    }


I have added the EJB module as a deployment assembly in my client project EAR. I can success fully call the add method in this way. But I want to deploy this EJB module as separate application in WebSphere server and call the add method. How can I do this. Please help me ...




You should create remote interface for it:


@Remote
public interface ICalRemoteBean{
public int add(int a, int b);
}

@Stateless
public class CalcEJBean implements /*ICalLocalBean*/ ICalRemoteBean {
@Override
public int add(int a, int b) {
return a + b;
}
}
public class CalcServlet extends HttpServlet {
@EJB
private /*ICalLocalBean*/ ICalRemoteBean iCalRemoteBean;
...
}

Read more here




Per section 3.2.2 of the EJB 3.1 specification:



Access to an enterprise bean through the local client view is only required to be supported for local clients packaged within the same application as the enterprise bean that provides the local client view. Compliant implementations of this specification may optionally support access to the local client view of an enterprise bean from a local client packaged in a different application. The configuration requirements for inter-application access to the local client view are vendor-specific and are outside the scope of this specification. Applications relying on inter-application access to the local client view are non-portable.



That said, WebSphere does support this with some limitations. See the Local Client Views section of the EJB Modules topic in the InfoCenter for more information.



I have created sample EJB 3 application with annotation in WebSphere 7. It is like this.



  1. The local interface

    @Local
    public interface ICalLocalBean{

    public int add(int a, int b);

    }

  2. Implementation of EJB.

    @Stateless
    public class CalcEJBean implements ICalLocalBean {

    @Override
    public int add(int a, int b) {
    return a + b;
    }

    }

  3. Access the EJB inside the servlet.

    public class CalcServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    @EJB
    private ICalLocalBean iCalLocalBean;

    ...

    }


I have added the EJB module as a deployment assembly in my client project EAR. I can success fully call the add method in this way. But I want to deploy this EJB module as separate application in WebSphere server and call the add method. How can I do this. Please help me ...



You should create remote interface for it:


@Remote
public interface ICalRemoteBean{
public int add(int a, int b);
}

@Stateless
public class CalcEJBean implements /*ICalLocalBean*/ ICalRemoteBean {
@Override
public int add(int a, int b) {
return a + b;
}
}
public class CalcServlet extends HttpServlet {
@EJB
private /*ICalLocalBean*/ ICalRemoteBean iCalRemoteBean;
...
}

Read more here



Per section 3.2.2 of the EJB 3.1 specification:



Access to an enterprise bean through the local client view is only required to be supported for local clients packaged within the same application as the enterprise bean that provides the local client view. Compliant implementations of this specification may optionally support access to the local client view of an enterprise bean from a local client packaged in a different application. The configuration requirements for inter-application access to the local client view are vendor-specific and are outside the scope of this specification. Applications relying on inter-application access to the local client view are non-portable.



That said, WebSphere does support this with some limitations. See the Local Client Views section of the EJB Modules topic in the InfoCenter for more information.


0 commentaires:

Enregistrer un commentaire