【问题标题】:Unable to access an EJB deployed in jboss as 7无法访问部署在 jboss 中的 EJB 为 7
【发布时间】:2016-09-25 14:41:12
【问题描述】:

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

以下是部署日志中有关 EJB 的 JNDI 绑定的内容。

19:21:43,269 信息 [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC 服务线程 1-1)命名为会话 bean 的 JNDI 绑定 部署单元部署“EJBTest1.jar”中的ManageEmployeeBean 为 如下:

java:global/EJBTest1/ManageEmployeeBean!com.test.ejb.businessimpl.ManageEmployeeBeanRemote java:app/EJBTest1/ManageEmployeeBean!com.test.ejb.businessimpl.ManageEmployeeBeanRemote java:module/ManageEmployeeBean!com.test.ejb.businessimpl.ManageEmployeeBeanRemote java:jboss/exported/EJBTest1/ManageEmployeeBean!com.test.ejb.businessimpl.ManageEmployeeBeanRemote java:global/EJBTest1/ManageEmployeeBean java:app/EJBTest1/ManageEmployeeBean java:module/ManageEmployeeBean

这就是我的客户端类的样子。

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中看到很多类似主题的主题,但没有一个对我有帮助!

【问题讨论】:

    标签: eclipse jakarta-ee jboss7.x jndi ejb-3.0


    【解决方案1】:

    您正在尝试使用 JBoss AS 5(或更早版本)的 EJB Remote 客户端。

    您需要使用 JBoss AS 7 EJB 远程客户端并按照 AS7 JNDI Reference 的文档在 Remote JNDI 标题下进行配置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-29
      • 2011-04-09
      • 2013-10-04
      • 2012-07-21
      • 2018-11-20
      • 1970-01-01
      • 2014-04-14
      相关资源
      最近更新 更多