Weblogic81中本地接口无状态session EJB该如何发布?

来源:互联网  时间:2016/8/31 10:57:02

关于网友提出的“ Weblogic81中本地接口无状态session EJB该如何发布?”问题疑问,本网通过在网上对“ Weblogic81中本地接口无状态session EJB该如何发布?”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题: Weblogic81中本地接口无状态session EJB该如何发布?
描述:

我做了一个无状态的session EJB,remote和local接口都有,然后发布在了Weblogic8.1中,但是有个奇怪的问题,remote接口访问正常,但是local接口无法访问。
部署过程中没有任何异常产生,而且console中的JIDI树中已存在相应的JIDI发布名称。唯一不同的是remote接口的JIDI名称后面有许多其它信息,而点击local接口的JIDI名称后只有一个名称,没有其它信息。
是发布配置文件的问题,还是Weblogic8.1的问题?


解决方案1:

如果是jsp调用确实需要打包ear文件,或者将jar(ejb部分)与war(veiw部分)放在同一个目录即可——也并不是已经需要打包成ear文件。
至于测试ejb,直接用我上面的ejbclient测试——通过网络都可以访问(三层结构,客户端采用application形式的,难道还需要把ejb也部署到client?)
想都可以想到:测试ejb的时候,client可以放在任何目录下,甚至网络上。只要网络没问题——根据weblogic的t3协议,连防火墙都可以穿过(书上的话,我没试过)!但局域网上我的client测试绝对成功!只要修改地址就可

解决方案2:

测试本地接口的话,另外一种方法,对这个本地接口的EJB生成一个对应的Facade sessionless ejb,暴露为remote接口。在对这个remote接口进行测试。
如果用jbuilder的话,上面所有测试代码都可以自动完成。
可能就麻烦了些

解决方案3:

呵呵,难道真的帮倒忙?
调用EJB本地接口的JSP或Servlet所属的WAR必须与EJB JAR统一打包到EAR文件中去。当该EAR被部署到WebLogic,JSP或Servlet才能调用EJB的本地接口。如果WAR和JAR单独部署,JSP或Servlet将不能调用EJB的本地接口,
这是bea dev2dev开发论坛的一篇文章写的,
http://dev2dev.bea.com.cn/bbs/school/guide/webser/20031158.html
我原来在sessionbean 中调用entitybean本地接口也不成功.
打成ear后调用成功
我的测试环境 weblogic 8.1 sp2
当然,如果不打包,我也希望,没必要那末麻烦
请问按照 kongyeeku(李别) ( 方法谁按照成功
如果真的给GreenCsdn (稻草人)麻烦 ,本人很抱歉.

解决方案4:

根本不是那样。(顺便说句:不懂的人,别乱给别人出主意,诶……)
完全不需要打包到一起。
我自己写的测试client的代码,你可以参考:
import javax.naming.*;
import java.util.Properties;
import javax.rmi.PortableRemoteObject;
public class helloClient extends Object
{
  private static final String ERROR_NULL_REMOTE = "remote接口不存在,必须先通过JNDI找到Home接口,然后创建remote接口";
  private static final int MAX_OUTPUT_LINE_LENGTH = 100;
  private boolean logging = true;
  private helloWorldHome hm = null;
  private helloWorld hw = null;
  //Construct the EJB test client
  public helloClient() {
    initialize();
  }
  public void initialize() {
    long startTime = 0;
    if (logging) {
      log("初始化hello World EJB的访问");
      startTime = System.currentTimeMillis();
    }
    try {
      //get naming context
      Context context = getInitialContext();
      //look up jndi name
      Object ref = context.lookup("helloWorld-demo");
      //look up jndi name and cast to Home interface
      hm = (helloWorldHome) PortableRemoteObject.narrow(ref, helloWorldHome.class);
      if (logging) {
        long endTime = System.currentTimeMillis();
        log("成功完成通过Home接口对EJB访问的初始化.");
        log("初始化执行时间: " + (endTime - startTime) + " ms.");
      }
    }
    catch(Exception e) {
      if (logging) {
        log("Home接口对EJB访问的初始化--失败!");
      }
      e.printStackTrace();
    }
  }
  private Context getInitialContext() throws Exception {
    String url = "t3://wonder:8181";
    String user = null;
    String password = null;
    Properties properties = null;
    try {
      properties = new Properties();
      properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
      properties.put(Context.PROVIDER_URL, url);
      if (user != null) {
        properties.put(Context.SECURITY_PRINCIPAL, user);
        properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
      }
      return new InitialContext(properties);
    }
    catch(Exception e) {
      log("不能连到WebLogic server在" + url);
      log("请检查Weblogic server是否运行,并且该EJB已经绑定到该server");
      throw e;
    }
  }
  //----------------------------------------------------------------------------
  // Methods that use Home interface methods to generate a Remote interface reference
  //----------------------------------------------------------------------------
  public helloWorld create() {
    long startTime = 0;
    if (logging) {
      log("引用create()开始创建remote接口的创建");
      startTime = System.currentTimeMillis();
    }
    try {
      hw = hm.create();
      if (logging) {
        long endTime = System.currentTimeMillis();
        log("create()执行成功,完成remote接口的创建");
        log("创建的执行时间: " + (endTime - startTime) + " ms.");
      }
    }
    catch(Exception e) {
      if (logging) {
        log("create()执行失败!");
      }
      e.printStackTrace();
    }
    if (logging) {
      log("create()的返回值: " + hw + ".");
    }
    return hw;
  }
  //----------------------------------------------------------------------------
  // 把EJB里的远程方法本地化----通过相同名字的方法内部调用远程方法完成EJB远程接口方法的本地化
  //----------------------------------------------------------------------------
  public String helloWorld(String strMsg)
  {
    log("以下是将EJB remote方法本地化来执行EJB中远程方法的调用");
String returnValue = "";
    if (hw == null) {
      System.out.println("Error in helloWorld(): " + ERROR_NULL_REMOTE);
      return returnValue;
    }
    long startTime = 0;
    if (logging) {
      log("开始调用helloWorld(" + strMsg + ")");
      startTime = System.currentTimeMillis();
    }
    try {
      returnValue = hw.helloWorld(strMsg);
      if (logging) {
        long endTime = System.currentTimeMillis();
        log("helloWorld(" + strMsg + ")执行成功");
        log("helloWorld(" + strMsg + ")执行时间: " + (endTime - startTime) + " ms.");
      }
    }
    catch(Exception e) {
      if (logging) {
        log("helloWorld(" + strMsg + ")方法的调用失败");
      }
      e.printStackTrace();
    }
    if (logging) {
      log("helloWorld(" + strMsg + ")方法的返回值: " + returnValue + ".");
    }
    return returnValue;
  }
  //----------------------------------------------------------------------------
  // Utility Methods
  //----------------------------------------------------------------------------
  private void log(String message) {
    if (message == null) {
      System.out.println("-- null");
      return ;
    }
    if (message.length() > MAX_OUTPUT_LINE_LENGTH) {
      System.out.println("-- " + message.substring(0, MAX_OUTPUT_LINE_LENGTH) + " ...");
    }
    else {
      System.out.println("-- " + message);
    }
  }
  //Main method
  public static void main(String[] args) {
    try{
      helloClient client = new helloClient();
      helloWorld remote = client.create();
      System.out.println(remote.helloWorld("************Demo one**********"));
  System.out.println(client.helloWorld("*Local Demo*"));
    }
    catch(Exception ex){
        ex.printStackTrace();
    }
  }
}
请把home接口与remote接口的class文件与此文件放在同一个文件夹。如果你的remote接口有包,home接口有package语句,则执行的时候还要正确调用remote接口与home接口。如果你还不能正确测试,绝对是你的EJB问题。

解决方案5:

呵呵,首先要考虑你本身的应用有没有必要用ejb本地接口,
本人不认为本地有用ejb的必要,
如果你要调试,很简单,
我已经说清楚了,bea不支持这样调用(我不清楚其他server)
要测试,将测试的web应用和你的ejb jar打成ear,
如果你用的是jbuilder的打包的话,很容易的

解决方案6:

调用EJB本地接口的JSP或Servlet所属的WAR必须与EJB JAR统一打包到EAR文件中去。当该EAR被部署到WebLogic,JSP或Servlet才能调用EJB的本地接口。如果WAR和JAR单独部署,JSP或Servlet将不能调用EJB的本地接口,我也遇到过,

解决方案7:

1、将session bean部署到weblogic8.1,部署成功会有相应提示
2、1 写一个测试类直接测试部署好的session bean
2、2 写个jsp页面部署到weblogic,通过jsp调用session bean

上一篇用JavaMail发送邮件时,如何才能把附件的Content-Type设置为 application/smil
下一篇WebLogic81配置问题~~, 各位给偶看看哪里没弄对~~~
明星图片
相关文章
《 Weblogic81中本地接口无状态session EJB该如何发布?》由码蚁之家搜集整理于网络,
联系邮箱:mxgf168#qq.com(#改为@)