您的位置:程序门 -> java -> j2ee / ejb / jms



ejb 远程方法调用出错


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


ejb 远程方法调用出错[已结贴,结贴人:yuchen2008]
发表于:2007-05-10 16:41:34 楼主
ide:netbeans
ejb   容器:system   application   server
ejb   3.0

接口
/*
  *   homer.java
  *
  *   created   on   2007年5月10日,   下午1:54
  *
  *   to   change   this   template,   choose   tools   ¦   template   manager
  *   and   open   the   template   in   the   editor.
  */

package   first;
import   javax.ejb.remote;
/**
  *
  *   @author   administrator
  */
@remote
public   interface   homer   {
        string   hello(string   user);
}

sessionbean:
/*
  *   hello.java
  *
  *   created   on   2007年5月10日,   下午1:56
  *
  *   to   change   this   template,   choose   tools   ¦   template   manager
  *   and   open   the   template   in   the   editor.
  */

package   first;

import   javax.ejb.stateless;

/**
  *
  *   @author   administrator
  */
@stateless
public   class   hello   implements   homer{
       
        /**   creates   a   new   instance   of   hello   */
        public   hello()   {
        }
        public   string   hello(string   user)   {
                return   "hello "   +user;
        }
       
}

客户端:
/*
  *   main.java
  *
  *   created   on   2007年5月10日,   下午1:59
  *
  *   to   change   this   template,   choose   tools   ¦   template   manager
  *   and   open   the   template   in   the   editor.
  */

package   test;

import   first.homer;
import   javax.naming.context;
import   javax.naming.initialcontext;
import   javax.naming.namingexception;

/**
  *
  *   @author   administrator
  */
public   class   main   {
       
        /**   creates   a   new   instance   of   main   */
        public   main()   {
        }
       
        /**
          *   @param   args   the   command   line   arguments
          */
        public   static   void   main(string[]   args)   throws   exception   {
                //   todo   code   application   logic   here
                context   context=new   initialcontext();
                homer   home=(homer)context.lookup( "first.homer ");
                system.out.println(home.hello( "yuchen "));
        }
       
}

错误提示:exception   in   thread   "main "   javax.naming.namenotfoundexception:   first.homer   not   found
发表于:2007-05-10 17:08:021楼 得分:40
exception   in   thread   "main "   javax.naming.namenotfoundexception:   first.homer   not   found
根据提示,first.homer找不到,不知道是程序没找到配置文件,还是配置文件中不存在这个名字。
发表于:2007-05-10 17:45:002楼 得分:0
我用的是ejb3.0   需要写配置文件吗?
发表于:2007-05-10 17:51:053楼 得分:0
我没用过,不是太清楚。
不过根据提示,肯定是找不到first.homer,也许是环境变量没有设置?
发表于:2007-05-11 12:28:084楼 得分:30
up
发表于:2007-05-11 13:07:505楼 得分:30
你需要在server中注册jndi名 "first.homer "
发表于:2007-05-22 00:11:526楼 得分:0
错误原因:客户端没有导入ejb模块的jar包


快速检索

最新资讯
热门点击