【问题标题】:Plug Bean to JBoss with JNDI使用 JNDI 将 Bean 插入 JBoss
【发布时间】:2012-12-07 14:49:16
【问题描述】:

我想知道如何使用 JNDI 将对象(如果我需要 EJB)插入到 JBoss (5.0) 中?

我的 Spring applicationContext.xml 中有以下 bean 定义:

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<tx:annotation-driven transaction-manager="transactionManager" />

<context:annotation-config/>

<bean id="myServiceFacade" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="MyServiceFacadeBean/remote"/>
    <property name="cache" value="true"/>
    <property name="lookupOnStartup" value="true"/>
    <property name="jndiEnvironment">
        <props>
            <prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory
            </prop>
            <prop key="java.naming.provider.url">localhost:1099</prop>
            <prop key="java.naming.factory.url.pkgs">org.jboss.naming:org.jnp.interfaces
            </prop>
        </props>
    </property>
    <property name="proxyInterface" value="my.company.service.facade.MyServiceFacade"/>
</bean>

当我尝试运行 JBoss 时,我得到:

Caused by: javax.naming.NameNotFoundException: MyServiceFacadeBean/remote
at org.jboss.ha.jndi.HAJNDI.lookupRemotely(HAJNDI.java:264)
at org.jboss.ha.jndi.HAJNDI.lookup(HAJNDI.java:205)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.ha.framework.interfaces.HARMIClient.invoke(HARMIClient.java:318)
at $Proxy165.lookup(Unknown Source)

也许应该采取一些额外的步骤来向 JBoss/JNDI 注册对象?

注意,我已经尝试将 ejb 特定文件放入 JBoss(jboss.xml、ejb-jar.xml),但这没有帮助。

【问题讨论】:

    标签: java spring jboss ejb jndi


    【解决方案1】:

    如何在 DataSource 中循环远程?但我确信您无法从您的 MyServiceFacadeBean 中获取它。

    在 applicationContext.xml 中:

    <property name="jndiName" value="remote"/>
    

    在循环时,

    Context ctx = new InitialContext();
    DataSource ds = (DataSource)ctx.lookup("java:comp/env/remote");
    DataSource ds = (DataSource)envCtx.lookup("remote");
    

    或者你可以做一个中间步骤,这样你就不必为你检索的每个资源指定“java:comp/env”:

    Context ctx = new InitialContext();
    Context envCtx = (Context)ctx.lookup("java:comp/remote");
    DataSource ds = (DataSource)envCtx.lookup("remote");
    

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-13
      • 1970-01-01
      • 2014-09-09
      • 1970-01-01
      • 2011-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多