如果部署没问题是不会有错的,你还可以到weblogic里的jms console里看看是否部署上去了,然后在检查一下

解决方案 »

  1.   

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

  2.   

    to beauty_beast(柳随风):
    那这样的话,本地接口的测试怎样来进行?我现在是将这个EJB单独打了一个jar包发布了,现在想测试它?
      

  3.   

    各位对于Local接口的EJB的单元测试是如何来做的?欢迎各位前来讨论。
      

  4.   

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

  5.   

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

  6.   

    那这样的话,local接口的ejb每次测试的时候都必须打包成ear。太麻烦了,有谁有更好的办法。
      

  7.   

    根本不是那样。(顺便说句:不懂的人,别乱给别人出主意,诶……)
    完全不需要打包到一起。
    我自己写的测试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问题。
      

  8.   

    至少session bean要打包部署到服务器吧
      

  9.   

    呵呵,难道真的帮倒忙?
    调用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 (稻草人)麻烦 ,本人很抱歉.
      

  10.   

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

  11.   

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

  12.   

    好了,感谢各位的积极参与!该问题现在可以结贴了。我对这个问题做一下总结,local接口的EJB测试时可以使用2种方式来进行:
    1、将war和jar打包成ear进行发布(或者直接将应用发布)测试。
    2、生成该local EJB的remote接口,通过remote接口测试local接口的相应功能,然后在具体发布时发布为local接口。所以,我觉得第2种方法在单元测试时比较方便一些,建议大家采用这种方式。只是在最终集成测试的时候别忘了将相应的配置文件修改为local接口。