本文介绍了我如何使用客户端 JSP/Servlet 在另一台计算机上部署会话 Bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是 EJB3 的新手,我知道如何在一台计算机的 Glassfish 服务器上部署会话 Bean(无状态或有状态).我的问题是:如何在计算机 A 上部署会话 bean 并在计算机 B 上部署 Servlet 或 JSP?它的意思是计算机 A 有会话 Bean 源和计算机 B 有 Servlet 或 JSP 源.如果使用 1 台计算机,我可以使用 @EJB 依赖注入查找会话 Bean但是在另一台计算机上,我该如何处理客户端代码?1台电脑示例

Hello Everybody i'm new in EJB3, i know how to deploy Session Bean (Stateless or stateful) on Glassfish server in one computer. My question is: how can i deploy session bean on Computer A and Deploy Servlet or JSP on Computer B?It meanComputer A have Session Bean Sourceand Computer B have Servlet or JSP source.if use 1 computer i can use @EJB dependency inject lookup Session Beanbut on another computer how can i do it for client code?Example for 1 computer

@EJB
private StatelessRemote remote ;

double Dosomething= remote.Dosomething();

out.println(Dosomething);

推荐答案

  1. 使用远程接口创建一个客户端 jar",部署在客户端

  1. Create a "client jar" with the remote interfaces, deploy in on the client

提供应用服务器客户端 jar(在您的场景中不需要)

Provide the app server client jar (not necessary in your scenario)

在类路径上提供一个 jndi.properties 并包含以下内容(假设 GlassFish 到 GlassFish 通信):

Provide a jndi.properties on the classpath with the following content (assuming GlassFish to GlassFish communication):

java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory
java.naming.factory.url.pkgs=com.sun.enterprise.naming
java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl
org.omg.CORBA.ORBInitialHost=<hostname>
org.omg.CORBA.ORBInitialPort=3700

  • 使用@EJB注解的mappedName属性指定目标Remote EJB组件的全局JNDI名称(如果没有jndi-name 在 sun-ejb-jar.xml 中设置 - 或者根本没有 sun-ejb-jar.xml - 全局 jndi-name 默认为完全限定的远程 3.0 业务接口类名):

  • Use the mappedName attribute of the @EJB annotation to specify the global JNDI name of the target Remote EJB component (If there is no jndi-name set in sun-ejb-jar.xml - or no sun-ejb-jar.xml at all - the global jndi-name defaults to the fully qualified Remote 3.0 Business interface class name) :

    @EJB(mappedName="com.acme.app.StatelessRemote")
    private StatelessRemote remote;
    

  • 资源

    05-22 05:05