如何解决 Spring 进程查找 EJB JNDI 端点的错误?

How to resolve error with Spring process looking for EJB JNDI endpoint?

我有一个 Apache Camel Spring 进程连接到 JBoss 4.2.3 应用程序服务器以获取 EJB 远程代理。 以下是配置文件的 XML 片段:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:camel="http://camel.apache.org/schema/spring"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/jee
        http://www.springframework.org/schema/jee/spring-jee.xsd
        http://camel.apache.org/schema/spring
        http://camel.apache.org/schema/spring/camel-spring.xsd"
       default-lazy-init="true">

    <!-- ================================ -->
    <!-- EJB Components -->
    <!-- ================================ -->

    <jee:remote-slsb id="brokingReferenceService"
                     jndi-name="BrokingReferenceServiceBean/remote"
                     business-interface="com.company.command.ejb.BrokingReferenceService"/>

    <jee:remote-slsb id="strategyReferenceService"
                     jndi-name="StrategyReferenceServiceBean/remote"
                     business-interface="com.company.command.ejb.StrategyReferenceService"/>

    <jee:remote-slsb id="instantMessageOrderService"
                     jndi-name="InstantMessageOrderServiceBean/remote"
                     business-interface="com.company.command.ejb.InstantMessageOrderService"/>
    ...
</beans>

我在类路径中有一个 jndi.properties 文件,其中包含以下内容:

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=http://10.10.0.240:1100

但是当进程尝试查找 JNDI 端点时我收到以下错误:

2017-01-03 09:15:07.057 DEBUG (org.springframework.jndi.JndiTemplate) Looking up JNDI object with name [java:comp/env/BrokingReferenceServiceBean/remote]
2017-01-03 09:15:09.322 DEBUG (org.jnp.interfaces.NamingContext) Failed to connect to http:1099
javax.naming.CommunicationException: Failed to connect to server http:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server http:1099 [Root exception is java.net.UnknownHostException: http]]
        at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:274)
        at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1533)
        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:417)
        at org.springframework.jndi.JndiTemplate.doInContext(JndiTemplate.java:154)
        at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
        at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
        at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
        at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
        at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
        at org.springframework.ejb.access.AbstractRemoteSlsbInvokerInterceptor.lookup(AbstractRemoteSlsbInvokerInterceptor.java:100)
        at org.springframework.ejb.access.AbstractSlsbInvokerInterceptor.refreshHome(AbstractSlsbInvokerInterceptor.java:122)
        at org.springframework.ejb.access.SimpleRemoteSlsbInvokerInterceptor.refreshHome(SimpleRemoteSlsbInvokerInterceptor.java:163)
        at org.springframework.ejb.access.AbstractSlsbInvokerInterceptor.afterPropertiesSet(AbstractSlsbInvokerInterceptor.java:109)
        ...
Caused by: javax.naming.ServiceUnavailableException: Failed to connect to server http:1099 [Root exception is java.net.U
nknownHostException: http]
        at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:248)
        ... 48 more
Caused by: java.net.UnknownHostException: http
        at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
        at java.net.InetAddress.lookupAllHostAddr(InetAddress.java:928)
        at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
        at java.net.InetAddress.getAllByName0(InetAddress.java:1276)
        at java.net.InetAddress.getAllByName(InetAddress.java:1192)
        at java.net.InetAddress.getAllByName(InetAddress.java:1126)
        at java.net.InetAddress.getByName(InetAddress.java:1076)
        at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:76)
        at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:244)
        ... 48 more

有没有人知道为什么它没有正确拾取 URL?我在属性文件中定义了 URL,但它正在将 URL 解析为 "http:1099"。

感谢您的帮助。

试试这些:

  • java.naming.provider.url=jnp://10.10.0.240:1100
  • java.naming.provider.url=10.10.0.240:1100

查看文档 here