Java 运行客户端类时EJB项目中的CommunicationException:无法获得到以下任何URL的连接:localhost:1099
我已经用JBoss5在EJB3.0中创建了一个helloworld应用程序。当我尝试运行客户端类EJBClient应用程序时,它会抛出一个异常 我经常会遇到以下异常情况。我已经做了很多关于它的研究,但我找不到它,因为我是EJB新手,请帮助 例外情况:Java 运行客户端类时EJB项目中的CommunicationException:无法获得到以下任何URL的连接:localhost:1099,java,jakarta-ee,jboss,Java,Jakarta Ee,Jboss,我已经用JBoss5在EJB3.0中创建了一个helloworld应用程序。当我尝试运行客户端类EJBClient应用程序时,它会抛出一个异常 我经常会遇到以下异常情况。我已经做了很多关于它的研究,但我找不到它,因为我是EJB新手,请帮助 例外情况: /** * Session Bean implementation class StatelessSessionBean */ package com.hex.statelessbean; import javax.ejb.Statel
/**
* Session Bean implementation class StatelessSessionBean
*/
package com.hex.statelessbean;
import javax.ejb.Stateless;
@Stateless
public class StatelessSessionBean implements StatelessSessionBeanRemote {
/**
* Default constructor.
*/
public StatelessSessionBean() {
// TODO Auto-generated constructor stub
}
@Override
public String displayMessage() {
// TODO Auto-generated method stub
return "Hello world";
}
javax.naming.CommunicationException:无法获取到的连接
以下URL之一:localhost:1099,发现失败,错误为:
javax.naming.CommunicationException:接收超时[根异常]
是java.net.SocketTimeoutException:Receive超时][根目录
异常为javax.naming.CommunicationException:连接失败
到服务器localhost/127.0.0.1:1099[根异常为
javax.naming.ServiceUnavailableException:无法连接到服务器
localhost/127.0.0.1:1099[根异常为java.net.ConnectException:
连接被拒绝:连接]]]at
org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1763)位于
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:693)位于
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)位于
javax.naming.InitialContext.lookup(InitialContext.java:392)位于
com.hex.client.EjbClientApplication.main(EjbClientApplication.java:28)
原因:javax.naming.CommunicationException:无法连接到
服务器localhost/127.0.0.1:1099[根异常为
javax.naming.ServiceUnavailableException:无法连接到服务器
localhost/127.0.0.1:1099[根异常为java.net.ConnectException:
连接被拒绝:连接]]位于
org.jnp.interfaces.NamingContext.getServer(NamingContext.java:335)位于
org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1734)。。。
4其他原因:javax.naming.ServiceUnavailableException:未能
连接到服务器localhost/127.0.0.1:1099[根异常为
java.net.ConnectException:连接被拒绝:连接]位于
org.jnp.interfaces.NamingContext.getServer(NamingContext.java:305)。。。
5其他原因:java.net.ConnectException:连接被拒绝:
连接在java.net.PlainSocketImpl.socketConnect(本机方法)
java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)位于
位于的java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
位于的java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
位于的java.net.socksocketimpl.connect(socksocketimpl.java:366)
java.net.Socket.connect(Socket.java:529)位于
org.jnp.interfaces.TimedSocketFactory.createSocket
(TimedSocketFactory.java:97)在
org.jnp.interfaces.TimedSocketFactory.createSocket
(TimedSocketFactory.java:82)在
org.jnp.interfaces.NamingContext.getServer(NamingContext.java:301)。。。
还有5个
Jboss服务器的端口是127.0.0.1:10001,但我试图点击这个url 127.0.0.1:1099,这是ryt吗
服务器属性:
package com.hex.statelessbean;
import javax.ejb.Remote;
@Remote
public interface StatelessSessionBeanRemote {
public String displayMessage();
}
package com.hex.client;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.hex.statelessbean.StatelessSessionBeanRemote;
public class EjbClientApplication {
public static void main(String[] args) {
try {
Properties props = new Properties();
props.setProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.factory.url.pkgs",
"org.jboss.naming");
props.setProperty("java.naming.provider.url", "localhost:1099");
InitialContext ctx = new InitialContext(props);
StatelessSessionBeanRemote bean = (StatelessSessionBeanRemote) ctx
.lookup("StatelessSessionBean/remote");
System.out.println("Message from Bean :" + bean.displayMessage());
} catch (NamingException e) {
e.printStackTrace();
}
}
}
- 地址:127.0.0.1
- 端口:8080
- JNDI端口:1099
package com.hex.statelessbean;
import javax.ejb.Remote;
@Remote
public interface StatelessSessionBeanRemote {
public String displayMessage();
}
package com.hex.client;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.hex.statelessbean.StatelessSessionBeanRemote;
public class EjbClientApplication {
public static void main(String[] args) {
try {
Properties props = new Properties();
props.setProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.factory.url.pkgs",
"org.jboss.naming");
props.setProperty("java.naming.provider.url", "localhost:1099");
InitialContext ctx = new InitialContext(props);
StatelessSessionBeanRemote bean = (StatelessSessionBeanRemote) ctx
.lookup("StatelessSessionBean/remote");
System.out.println("Message from Bean :" + bean.displayMessage());
} catch (NamingException e) {
e.printStackTrace();
}
}
}
无状态bean:
/**
* Session Bean implementation class StatelessSessionBean
*/
package com.hex.statelessbean;
import javax.ejb.Stateless;
@Stateless
public class StatelessSessionBean implements StatelessSessionBeanRemote {
/**
* Default constructor.
*/
public StatelessSessionBean() {
// TODO Auto-generated constructor stub
}
@Override
public String displayMessage() {
// TODO Auto-generated method stub
return "Hello world";
}
}
客户端:
package com.hex.statelessbean;
import javax.ejb.Remote;
@Remote
public interface StatelessSessionBeanRemote {
public String displayMessage();
}
package com.hex.client;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.hex.statelessbean.StatelessSessionBeanRemote;
public class EjbClientApplication {
public static void main(String[] args) {
try {
Properties props = new Properties();
props.setProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.factory.url.pkgs",
"org.jboss.naming");
props.setProperty("java.naming.provider.url", "localhost:1099");
InitialContext ctx = new InitialContext(props);
StatelessSessionBeanRemote bean = (StatelessSessionBeanRemote) ctx
.lookup("StatelessSessionBean/remote");
System.out.println("Message from Bean :" + bean.displayMessage());
} catch (NamingException e) {
e.printStackTrace();
}
}
}
将本地主机:1099更改为jnp://localhost:1099和
org.jboss.naming到org.jboss.naming:org.jnp.interfaces
并检查ejb的名称。使用注释@RemoteBinding
可以为ejb命名。您有端口偏移量吗?将localhost:1099更改为jnp://localhost:1099
和org.jboss.naming到org.jboss.naming:org.jnp.interfaces
并检查ejb的名称。使用注释@RemoteBinding
可以为ejb命名。您有端口偏移量吗?我已经做了更改,但即使遇到相同的异常情况。@JayanthiM您的服务器配置中的JNDI端口是什么?您是否在服务器日志或JMX控制台中看到您的EJB?是否可以尝试将java.naming.factory.url.pkgs值更改为org.jboss.naming.client?在服务器配置中,JNDI端口为1099,端口为8080,我已经将值更改为org.jboss.naming:org.jnp.interfaces,但我经常遇到这个异常。javax.naming.CommunicationException:无法获取到这些URL中任何一个的连接:localhost:1099,发现失败,错误为:javax.naming.CommunicationException:Receive Timeout[根异常为java.net.SocketTimeoutException:Receive Timeout]Hi我可以知道jboss 5Hi awagenhoffer的默认JNDI端口是什么吗,谢谢你的及时回复和帮助。在Jboss As5服务器中,绑定部署的conf文件夹中的Jboss beans xml文件,我将命名服务的端口更改为默认的1099,这样就可以正常工作了。谢谢:)我已经做了更改,但即使我得到了相同的异常。@JayanthiM您的服务器配置中的JNDI端口是什么?您是否在服务器日志或JMX控制台中看到您的EJB?是否可以尝试将java.naming.factory.url.pkgs值更改为org.jboss.naming.client?在服务器配置中,JNDI端口为1099,端口为8080,我已经将值更改为org.jboss.naming:org.jnp.interfaces,但我经常遇到这个异常。javax.naming.CommunicationException:无法获取到这些URL中任何一个的连接:localhost:1099,发现失败,错误为:javax.naming.CommunicationException:Receive Timeout[根异常为java.net.SocketTimeoutException:Receive Timeout]Hi我可以知道jboss 5Hi awagenhoffer的默认JNDI端口是什么吗,谢谢你的及时回复和帮助。在Jboss As5服务器中,绑定部署的conf文件夹中的Jboss beans xml文件,我将命名服务的端口更改为默认的1099,这样就可以正常工作了。谢谢:)
Corrected Code:
**Interface class:**
package com.hex.statelessbean;
import javax.ejb.Remote;
@Remote
public interface StatelessSessionBeanRemote {
public String displayMessage();
}
**Stateless Bean class:**
package com.hex.statelessbean;
import javax.ejb.Stateless;
/**
* Session Bean implementation class StatelessSessionBean
*/
@Stateless
public class StatelessSessionBean implements StatelessSessionBeanRemote {
/**
* Default constructor.
*/
public StatelessSessionBean() {
// TODO Auto-generated constructor stub
System.out.println("************* Calling from Default constructor ******************");
}
@Override
public String displayMessage() {
// TODO Auto-generated method stub
System.out.println("************* Calling from displayMessage() ******************");
return "Hello world";
}
}
**Client class:**
package com.hex.client;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.hex.statelessbean.StatelessSessionBeanRemote;
public class EjbClientApplication {
/**
* @param args
* @throws NamingException
*/
public static void main(String[] args) {
try {
Properties properties = new Properties();
properties.setProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
properties.setProperty("java.naming.factory.url.pkgs",
"org.jboss.naming:org.jnp.interfaces");
properties.setProperty("java.naming.provider.url",
"jnp://localhost:1099");
InitialContext ctx = new InitialContext(properties);
StatelessSessionBeanRemote bean = (StatelessSessionBeanRemote) ctx
.lookup("StatelessSessionBean/remote");
System.out.println("Message from Bean :" + bean.displayMessage());
} catch (NamingException e) {
e.printStackTrace();
}
}
}
**LookUp:**
Message from Bean :Hello world