在使用jboss-4.2.3.GA发布EJB3.0服务的时候,采用默认的jboss配置(也就是配置文件不做任何变更,启动服务的时候也不附加任何参数),可以在本地使用localhost:1099
也就是这里
class="java">
props.setProperty(Context.PROVIDER_URL, "localhost:1099");
后来,希望将服务部署在一台机器上(服务器),用另外的机器(客户端)调用服务器上的服务,体验ejb的分布式服务。于是便将服务器启动了,在客户端使用这样的代码(服务器地址是150.18.23.128):
props.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
props.setProperty(Context.PROVIDER_URL, "150.18.23.128:1099");
连接服务器。结果,客户端说服务器不鸟ta,
。客户端是这样说的:
javax.naming.CommunicationException: Could not obtain connection to any of these urls: 150.18.23.128:1099 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] [Root exception is javax.naming.CommunicationException: Failed to connect to server 150.18.23.128:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server 150.18.23.128:1099 [Root exception is java.net.ConnectException: Connection timed out: connect]]]
at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1562)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:634)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at com.foshanshop.ejb3.app.MyQueueSender.main(MyQueueSender.java:33)
Caused by: javax.naming.CommunicationException: Failed to connect to server 150.18.23.128:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server 150.18.23.128:1099 [Root exception is java.net.ConnectException: Connection timed out: connect]]
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:274)
at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1533)
... 4 more
Caused by: javax.naming.ServiceUnavailableException: Failed to connect to server 150.18.23.128:1099 [Root exception is java.net.ConnectException: Connection timed out: connect]
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:248)
... 5 more
Caused by: java.net.ConnectException: Connection timed out: connect
于是刘若英大姐开唱了:后来…………
后来,查了很多资料,试了一大通,试过配置host,修改jboss的配置文件,修改连接的url……
行不通……
最后 通过 搜索:jboss.bind.address,找到了 http://feng88724.iteye.com/blog/263211:Jboss无法通过IP地址访问,只能用localhost\127.0.0.1访问
(感谢该博文帮主我解决了问题^_^)
于是,这样处理
在jboss\jboss-4.2.3.GA\bin 新建了 startmy.bat,在里面添加以下内容
run.bat -b 0.0.0.0
运行startmy.bat启动服务,这样客户端就可以访问
服务端的服务了,配置还是
props.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
props.setProperty(Context.PROVIDER_URL, "150.18.23.128:1099");
另外一种启动的方式是: 在cmd中运行 run.bat -b 0.0.0.0,效果是一样的