您的位置:首页 > 运维架构

EJB3.0异常总结--- Need to specify class name in environment or system property,

2013-01-05 20:43 447 查看
异常:

Need to specify class name in environment or system property, or

as an applet parameter, or in an application resource file:

java.naming.factory.initial

原因:

1.没有写入jndi.properties.

2.Need to specify class name in environment or system property. 的

意思就是找不到你的EJB环境变量. 换句话说就是你的客户在使用lookup

的时候. context没有设置对.

3.Need to specify class name in environment or system property, or

as an applet parameter, or in an application resource file:

java.naming.factory.initial

使用的是代码InitialContext

ctx=new InitialContext(props);的方式,不存在jndi配置文件不对的问

题,最后想起之前一个教程里的一句命名空间的话,于是登录jboss控制

台,找到部署的ejb,前面一个java提醒鸟我,将代码里lookup中参数前

面加上java:,搞定。

public class EjbClient {

public static void main(String[] args) {

Properties props=new Properties();

props.setProperty

("java.naming.factroy.initial","org.jnp.interfaces.NamingContextFact

ory");

props.setProperty

("java.naming.provider.url","localhost:1099");//或者

jnp://localhost...也可

props.setProperty("java.naming.factory.url.pkgs",

"org.jboss.naming:org.jnp.interfaces");//此行必须有

try{

InitialContext ctx=new InitialContext(props);

HelloWorld helloworld=(HelloWorld)ctx.lookup

("java:HelloWorldBean/remote");//前面的java是关键

System.out.println(helloworld.sayHello("jack"));

}catch(NamingException e){

System.out.println("error:"+e.getMessage());

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐