我看的是尚学堂的的EJB课程,就是李鹏飞的那个,跟着他做,第一个小例子就卡住了,请大家救救小女吧,问题如下遇到问题: FirstEjbBean not bound javax.naming.NameNotFoundException: FirstEjbBean not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:126)
at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at com.mxf.ejb.FirstEjbClient.main(FirstEjbClient.java:22) 4.我的代码如下:
--接口
package com.mxf.ejb;
public interface FirstEjb {
public String sayHello(String str);
} --接口实现Bean
package com.mxf.ejb;
import javax.ejb.Remote;
import javax.ejb.Stateless;
@Remote
@Stateless
public class FirstEjbBean implements FirstEjb {
public String sayHello(String str) {
return "您好!"+str;
}
} --客户端
package com.mxf.ejb;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class FirstEjbClient {
public static void main(String[] args) {
try {
InitialContext itx = new InitialContext();
FirstEjb firstEjb = (FirstEjb)itx.lookup("FirstEjbBean/remote"); ---执行到这里报错
String str=firstEjb.sayHello("remain");
System.out.println(str);
} catch (NamingException e) {
e.printStackTrace();
}
}
}
at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:126)
at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at com.mxf.ejb.FirstEjbClient.main(FirstEjbClient.java:22) 4.我的代码如下:
--接口
package com.mxf.ejb;
public interface FirstEjb {
public String sayHello(String str);
} --接口实现Bean
package com.mxf.ejb;
import javax.ejb.Remote;
import javax.ejb.Stateless;
@Remote
@Stateless
public class FirstEjbBean implements FirstEjb {
public String sayHello(String str) {
return "您好!"+str;
}
} --客户端
package com.mxf.ejb;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class FirstEjbClient {
public static void main(String[] args) {
try {
InitialContext itx = new InitialContext();
FirstEjb firstEjb = (FirstEjb)itx.lookup("FirstEjbBean/remote"); ---执行到这里报错
String str=firstEjb.sayHello("remain");
System.out.println(str);
} catch (NamingException e) {
e.printStackTrace();
}
}
}
解决方案 »
- struts2关于select标签判断的问题
- if else
- jxl合并单元格,读该合并之后的单元格,读出数据出现与单元格数据不一致问题,请熟悉jxl的兄弟入(附代码)
- 猎头职位:手机项目管理工程师
- 小小的问题,struts总跳到上一层目录
- 学校刚开JAVA,大虾们帮忙看个这个程序???
- 求OpenNMS的相关资料
- 求在JMS里面使用XASESSION完成分布式两阶段提交事务处理的代码 100分 着急 在线
- 标题:一个jsp小问题,各位兄弟帮帮忙
- 关于两条SQL语句的性能疑惑,大家来看看
- 谁可以讲解一下struts整合hibernate的步骤啊
- 关于spring+hibernate调用oracle自定义函数的问题
请说一下吧
没有jems-installer-1.2.0.GA.jar 这个安装包的缘故啊,但是我下载解压并配置后,
输入http://localhost:8080/jmx-console/,也能进入JBOSS的页面啊,
到底什么原因啊
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.*;
import java.util.Properties;
public class FirstEjbClient {
public static void main(String[] args) {
Properties props=new Properties();
props.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.provider.url", "localhost:1099");
props.setProperty("Java. naming.factory.url.pkgs", "org.jboss.naming");
try {
InitialContext itx = new InitialContext(props);
FirstEjb firstEjb = (FirstEjb)itx.lookup("FirstEjbBean/remote"); ---执行到这里报错
String str=firstEjb.sayHello("remain");
System.out.println(str);
} catch (NamingException e) {
e.printStackTrace();
}
}
}
试一试
import javax.ejb.Remote;
import javax.ejb.Stateless;
@Remote ( {FirstEjb.class } )
@Stateless
public class FirstEjbBean implements FirstEjb {
public String sayHello(String str) {
return "您好!"+str;
}
} 再加上这个看看,我最近也在学ejb3.0,但一直没时间做例子,刚好