Jboos中 javax.naming.NameNotFoundException: StatfulEjbBean not bound

来源:百度知道 编辑:UC知道 时间:2024/05/15 23:46:58
刚学Jboos用的是Myeclipse,刚写第一个程序就不会了。运行Jboos客户端是出现此异常,请问是我程序错了还是Jboss安的不对啊?
jndi.properties
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=localhost
客户端程序:
package com.qqq.ejb;

import javax.naming.InitialContext;

public class FirstEjbClient {
public static void main(String args[]) throws Exception {
InitialContext context = new InitialContext();
FirstEjb firstEjb = (FirstEjb) context.lookup("FirstEjbBean/remote");
String s = firstEjb.saySome("张三");
System.out.println(s);

}
}
服务端程序:
package com.qqq.ejb;

public interface FirstEjb {
public String sySome(String name);
}

package com.qqq.ejb;

import javax.ejb.Remote;
import javax.ejb.Stateless;

@Stateless
@Remote
public class FirstEjbBean

@Remote should be applied to your ejb interface, ie FirstEjb

you must have another ejb called "StatfulEjbBean" which was not properly annotated. since jboss complained about it, not the ejb you listed here.

since the ejb client is a standalone java application in your example, resource injection might not be working, as the above suggestion of using @EJB.

最好用注入,
@EJB FirstEjb firstejb
.....
firstejb.saySome("李四");
用JNDI的LookUp是不具备移植性的,JBoss和WEBLogic的JNDI都不同,而且代码量多