这几天学习了一下EJB,刚开始搭建环境,配置JBOSS服务器后,创建第一个无状态会话Bean( stateless Session bean)HelloWord,运行客户端连接时报异常:java.net.SocketTimeoutException: Receive timed out。
下面是我的ejb client:
package com.ejb.junit; import java.util.Properties; import javax.naming.InitialContext; import javax.naming.NamingException; import com.ejb.HelloWorldRemote; public class EJBTest { public static void main(String[] args) { Properties prop=new Properties(); prop.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); prop.setProperty("java.nameing.provider.url", "jnp://127.0.0.1:1099"); prop.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces"); // prop.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); // prop.setProperty(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099"); // prop.setProperty(InitialContext.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); try { InitialContext ctx=new InitialContext(prop); HelloWorldRemote helloworld=(HelloWorldRemote)ctx.lookup("HelloWorld/remote"); System.out.println(helloworld.sayHello("World")); System.out.println(helloworld.sayHello("China")); } catch (NamingException e) { e.printStackTrace(); } } }
运行时异常堆栈如下:
javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1690) at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1812) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:695) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:688) at javax.naming.InitialContext.lookup(InitialContext.java:392) at com.ejb.junit.EJBTest.main(EJBTest.java:28) Caused by: java.net.SocketTimeoutException: Receive timed out at java.net.PlainDatagramSocketImpl.receive0(Native Method) at java.net.PlainDatagramSocketImpl.receive(PlainDatagramSocketImpl.java:145) at java.net.DatagramSocket.receive(DatagramSocket.java:725) at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1659) ... 5 more
网上找了好些方法都没法解法,最后在一个网站上看着直接用类的常量来代替,就是将上面绿字注释去掉,三行红字打上注释后,居然奇迹般的运行正常了。。真是让我费解,如果大家碰到这种问题,可以试下这个方法。我把类的常量打印出来,跟上面的是一样的,哎,想不明白,如果有知道问题答案或是有解决办法的高人的话,还请指点在下。。。
相关推荐
java.io.Reader 和 java.io.InputStream 的区别
Exception in thread “main” redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out at redis.clients.util.RedisInputStream.ensureFill...
广东外语外贸大学思科信息学院计算机专业JAVA课程专业中的一小段代码
code:500 msg: java.net.SocketTimeoutException: connect timed out at com.alibaba.nacos.client.naming.net.NamingProxy.callServer(NamingProxy.java:424) at ...
报错信息: can not resolve hostname 解决方法:去C:\Windows\System32\drivers\etc\hosts 里配置一下这个hostname和对应的IP ...Fri Feb 14 10:30:36 CST 2020, null, java.net.SocketTimeoutException: callTimeou
主要介绍了java socket长连接中解决read阻塞的3个办法,本文取了折中的一个方法,并给出代码实例,需要的朋友可以参考下
poi处理excel文件的小程序:自己写的poi处理excel文件的小程序,直接可以使用
android客户端通过webservice 获取天气预报 本人测试 绝对可用
在该分析服务的日志中发现了某个数据库操作产生了 SocketTimeoutException。 开发同学一开始希望通过调整 MongoDB Java Driver 的超时参数来规避这个问题。 但经过详细分析之后,这样是无法根治问题的,而且超时配置...