java - 我无法设置我的 jndi.properties 来访问 Jboss 5 上的远程 EJB

标签 java jboss ejb ejb-3.0 jboss5.x

我正在尝试设置 Jboss 服务器“客户端”(版本 5.1.0)以使用来自另一个 Jboss 服务器(10.90.0.91)的远程 EJB,但我无法使用Jboss 客户端。

我可以在我的客户端上使用这个简单的代码获取远程 EJB:

        InitialContext ctx = null;
        try {
            Hashtable<String, String> jndiProps = new Hashtable<String, String>();
            jndiProps.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
            jndiProps.put(InitialContext.PROVIDER_URL, "jnp://10.90.0.91:1099");
            ctx = new InitialContext(jndiProps);
            return ctx.lookup(jndiName);
        } catch (NamingException e) {
            throw new RuntimeException(e);
        }

这很好用。

现在我想用这个属性设置 Jboss 客户端。但是,如果我从以下位置编辑 server/{application}/conf/ 上本地化的现有 jndi.properties 文件:

# DO NOT EDIT THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING
#
java.naming.factory.initial=org.jboss.iiop.naming.ORBInitialContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

收件人:

# DO NOT EDIT THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING
#
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=jnp://10.90.0.91:1099

当我启动 Jboss 客户端时收到一些错误(显然,我不知道我在做什么 :)):

2016-08-19 10:17:41,645 ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController] (main) Error installing to Start: name=HASessionStateService state=Create
javax.naming.NameAlreadyBoundException: Default
    at org.jnp.server.NamingServer.bind(NamingServer.java:209)
    at org.jnp.server.NamingServer.bind(NamingServer.java:167)
[...]

2016-08-19 10:17:42,767 ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController] (main) Error installing to Start: name=ProfileServiceProxyFactory state=Create
javax.naming.NameAlreadyBoundException: ProfileService
    at org.jnp.server.NamingServer.bind(NamingServer.java:209)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[...]

2016-08-19 10:17:44,778 ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController] (main) Error installing to Start: name=jboss:service=ClientUserTransaction state=Create mode=Manual requiredState=Installed
javax.naming.NameAlreadyBoundException: UserTransaction
    at org.jnp.server.NamingServer.bind(NamingServer.java:209)
    at sun.reflect.GeneratedMethodAccessor487.invoke(Unknown Source)
[...]

在 final 中:

2016-08-19 10:17:51,993 ERROR [org.jboss.system.server.profileservice.ProfileServiceBootstrap] (main) Failed to load profile: Summary of incomplete deployments (SEE PREVIOUS ERRORS FOR DETAILS):

DEPLOYMENTS MISSING DEPENDENCIES:
  Deployment "ProfileServiceInvocationHandler" is missing the following dependencies:
    Dependency "ProfileServiceProxyFactory" (should be in state "Configured", but is actually in state "**ERROR**")
    Dependency "ProfileServiceProxyFactory" (should be in state "Configured", but is actually in state "**ERROR**")

DEPLOYMENTS IN ERROR:
  Deployment "jboss:service=ClientUserTransaction" is in error due to the following reason(s): javax.naming.NameAlreadyBoundException: UserTransaction
  Deployment "HASessionStateService" is in error due to the following reason(s): javax.naming.NameAlreadyBoundException: Default
  Deployment "ProfileServiceProxyFactory" is in error due to the following reason(s): javax.naming.NameAlreadyBoundException: ProfileService, **ERROR**

所以,我认为我不能触及该文件上已经存在的 JNDI 属性。

如果因为 JBoss 本身正在使用 jndi.properties 文件而无法更改,我可以在哪个位置将 JNDI 查找设置设置为 Jboss 5 中的远程 EJB?如何在不将 jndi.properties 文件放入 WAR 文件的情况下将 jndi.properties 文件配置为在应用程序类路径中可用?

谢谢!

最佳答案

另一种方法是在您的 jboss-service.xml 文件中配置 org.jboss.naming.ExternalContext MBean:

<mbean code="org.jboss.naming.ExternalContext" 
       name="jboss.jndi:service=ExternalContext,jndiName=external/server2">
    <attribute name="JndiName">external/server2</attribute>
    <attribute name="Properties">
        java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
        java.naming.provider.url=jnp://10.90.0.91:1099
        <!-- other properties as needed -->
    </attribute>
    <attribute name="InitialContext"> javax.naming.IntialContext </attribute>
    <attribute name="RemoteAccess">false</attribute>
</mbean>

执行查找的 java 代码将变为:

 Context initialContext = new InitialContext();
 return initialContext.lookup("external/server2/" + jndiName);

设置时,您甚至可以在本地管理控制台中使用 JNDIView 导航远程 JNDI 树。

更多信息可以在 org.jboss.naming.ExternalContext MBean 中找到.

关于java - 我无法设置我的 jndi.properties 来访问 Jboss 5 上的远程 EJB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39041794/

相关文章:

java - jOOQ 子查询给出编译错误“SelectWhereStep 类型中的方法 where(Condition...)...不适用于参数

java - 野蝇15 : Failed to process phase STRUCTURE of deployment

xml - 用于添加嵌套 xml 元素的 Jboss cli 命令

java - 将用户主体从 REST 传播到 EJB 层

java - 启动默认浏览器并获取 url

java - Joda 时间模式不正确?显示错误的日期

java - 正则表达式检查字符串第一个字符是否是数字

postgresql - 为两个不同的服务器使用相同的 postgresql 数据库有什么问题吗?

java - 多个具有相同名称的 EJB bean

java - 通过 RMI 的 ADF 业务组件与 EJB 和 Toplink