当前位置: 首页 > 知识库问答 >
问题:

无法访问部署在jboss as 7中的EJB

公孙阳羽
2023-03-14

我在Jboss 7.0中部署了一个EJB。

package com.test.ejb.test;

import java.util.Hashtable;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.test.ejb.bean.Employee;
import com.test.ejb.businessimpl.ManageEmployeeBean;
import com.test.ejb.businessimpl.ManageEmployeeBeanRemote;

public class Client {

    private static InitialContext initialContext;

    public static void main(String[] args){
        try {
            getInitialContext();
            System.out.println("CTX:"+initialContext);
        } catch (NamingException e) {
            e.printStackTrace();
        }

        try {
            System.out.println("Looking up EJB !!");
            ManageEmployeeBeanRemote remote = 
                    (ManageEmployeeBeanRemote)initialContext.lookup("/EJBTest1/ManageEmployeeBean!com.test.ejb.businessimpl.ManageEmployeeBeanRemote");
            System.out.println("setting employee..............");
            Employee employee = new Employee();
            employee.setFirstName("Renjith");
            employee.setLastName("Ravi");

            System.out.println("Adding employee");
            remote.addEmployee(employee);
        } catch (NamingException e) {
            e.printStackTrace();
        }
    }

    public static InitialContext getInitialContext() throws NamingException {
        if (initialContext == null) {
            Properties prop = new Properties();
            prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
            prop.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
            prop.put(Context.PROVIDER_URL, "remote://localhost:4447");
            prop.put(Context.SECURITY_PRINCIPAL, "renjith");
            prop.put(Context.SECURITY_CREDENTIALS, "user");
            initialContext = new InitialContext(prop);
        }
        return initialContext;
    }


}

当我运行该服务时,客户端无法找到该服务。

CTX:javax.naming.InitialContext@40964823
Looking up EJB !!
javax.naming.CommunicationException: Could not obtain connection to any of these urls: remote://localhost:4447 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 remote:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server remote:1099 [Root exception is java.net.UnknownHostException: remote: Name or service not known]]]
    at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1416)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:596)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:589)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at com.test.ejb.test.Client.main(Client.java:29)
Caused by: javax.naming.CommunicationException: Failed to connect to server remote:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server remote:1099 [Root exception is java.net.UnknownHostException: remote: Name or service not known]]
    at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:269)
    at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1387)
    ... 4 more
Caused by: javax.naming.ServiceUnavailableException: Failed to connect to server remote:1099 [Root exception is java.net.UnknownHostException: remote: Name or service not known]
    at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:243)
    ... 5 more
Caused by: java.net.UnknownHostException: remote: Name or service not known
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
    at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901)
    at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1293)
    at java.net.InetAddress.getAllByName0(InetAddress.java:1246)
    at java.net.InetAddress.getAllByName(InetAddress.java:1162)
    at java.net.InetAddress.getAllByName(InetAddress.java:1098)
    at java.net.InetAddress.getByName(InetAddress.java:1048)
    at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:76)
    at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:239)
    ... 5 more

谁能告诉我我在这里遗漏了什么?我在stackoverflow中看到了很多类似主题的线程,但没有一个对我有帮助!!

共有1个答案

长孙硕
2023-03-14

您试图使用JBoss AS 5(或更早版本)中的EJB远程客户端。

您需要使用JBoss AS 7 EJB远程客户机,并根据AS7 JNDI参考中Remote JNDI标题下的文档对其进行配置。

 类似资料:
  • 我是Spring mvc的新手,我已经按照入门指南导入了Spring工具套件中的应用程序()。它使用嵌入式Tomcat servlet作为独立应用程序运行良好。 然后,我开始将应用程序打包为战争。实际采取的步骤如下: 使应用程序类扩展SpringBootServletializer,并添加SpringApplicationBuilder配置方法 将嵌入式tomcat设置为提供的 将Maven打包设

  • 我在Google Container Engine上部署了一个容器,它运行良好。现在,我想公开它。 这个应用程序是一个侦听2个端口的服务。使用kubectl公开部署,我创建了2个负载均衡器,每个端口一个。 我制作了两个负载平衡器,因为kubectl expose命令似乎不允许使用多个端口。虽然我在kubectl上将其定义为type=LoadBalancer,但一旦在GKE上创建了它们,它们就被定义

  • 我有一个Spring启动Rest服务项目,它在我的本地机器上工作。当我运行应用程序为"Spring Boot App" 我可以通过转到访问rest服务 http://127.0.0.1:8080/persons/all 它返回JSON,因为它应该。 我换了pom。xml打包到war,然后我创建了一个war,作为- war文件名为“myapp-0.0.1-SNAPSHOT.war”,上传后,我试图通

  • 本文向大家介绍浅析docker-compose部署mysql无法访问的问题,包括了浅析docker-compose部署mysql无法访问的问题的使用技巧和注意事项,需要的朋友参考一下 什么是Docker-Compose Compose项目来源于之前的fig项目,使用python语言编写,与docker/swarm配合度很高。Compose 是 Docker 容器进行编排的工具,定义和运行多容器的应

  • 我假设上述证书的路径是主机上的路径,python脚本将从中获取文件,然后进行YAML构建? 测试呼叫3: 测试呼叫4:

  • < br > 我正在将JavaEE项目从Sun Application Server 9.1迁移到Glassfish 3.1.2。该项目具有以下结构: ear |-/lib/someProject。jar(由confictEJB和EJB使用) |-confictEJB。jar |-EJB。jar |-webProj.war 罐子和耳朵是用maven构建的。问题是,这在SAS 9.1和Glassfi