在客户端和实际应用程序位于不同容器中时配置事务管理器

时间:2014-02-07 10:02:12

标签: java spring tomcat jboss transactions

我在JBoss5中部署了第三方应用程序。第三方应用程序为我们提供了一个 AppClient.java 类,我们可以通过实例化并将一些连接属性传递给它来连接它。第三方应用程序获取一些数据并保存到数据库中。

现在我编写了一个独立的java类来连接到Thirdparty应用程序并启动以下事务。

         InitialContext initialContext = appClientReference.getInitialContext();


        tx = (UserTransaction)initialContext.lookup("UserTransaction");

        //Begin transaction
        tx.begin();

        //do some db operations by calling third party logic

        // Commit results
        tx.commit();

现在我想删除独立程序并创建一个Web应用程序并部署到 Tomcat 。所以,我的应用程序将在Tomcat中,第三方应用程序在JBoss中。现在我该如何开始交易?我正在使用spring3。 我可以使用任何Spring配置吗?

1 个答案:

答案 0 :(得分:0)

您始终可以使用spring bean创建appClientReference实例。

<bean id="demoLookup"
        class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="cache" value="true" />
        <property name="lookupOnStartup" value="true" />
        <property name="proxyInterface" value="your fully qualified look up business interface" />
        <property name="jndiName" >
            <value>contextName/ejbName/remote or local </value>  // assuming you have not over ridden the default naming strategy.
        </property>
        <property name="jndiEnvironment">
             <props>
               <prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
               <prop key="java.naming.provider.url">jnp://localhost:1099</prop>
               <prop key="java.naming.factory.url.pkgs">org.jboss.naming:org.jnp.interfaces</prop>
             </props>
       </property>
    </bean>