EJB的无状态会话,总是出错
刚开始学EJB,我用Myeclipse+jboss4的环境,做了一个测试例子,
接口
package com.foxhis.myejb.remote;
public interface MyFirstRemote {
public String getText(String name);
}
接口实现:
package com.foxhis.myejb.session;
import javax.ejb.*;
import com.foxhis.myejb.remote.MyFirstRemote;
@Stateless()
@Remote(MyFirstRemote.class)
public class MyFirstBean implements MyFirstRemote{
public String getText(String name){
String str = "Hello"+name;
return str;
}
}
client程序:
package com.foxhis.myejb.client;
import java.util.*;
import javax.naming.*;
import com.foxhis.myejb.remote.MyFirstRemote;
public class MyFirstClient {
public static void main(String[] args){
Properties props = new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
props.setProperty(Context.PROVIDER_URL, "localhost:8000");
props.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
try{
System.out.println("1");
InitialContext ctx = new InitialContext(props);
System.out.println("2");
MyFirstRemote my= (MyFirstRemote)ctx.lookup("MyFirstBean/remote");
System.out.println("3");
String str = my.getText("Xiaoxiao");
System.out.println("4");
System.out.println(str);
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
}
发布是成功了,结果在控制台出来的是:
1
2
Could not obtain connection to any of these urls: localhost:8000 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out]
就是到
MyFirstRemote my= (MyFirstRemote)ctx.lookup("MyFirstBean/remote");这步出错了,搞了半天,也在网是查了好久,就是没有一个适合的解决方法
求高人指教!!!!!!!!!
[解决办法]
默认的 JBoss JNDI 是 jnp://localhost:1099.