在spring boot上配置bitronix事务管理器以连接oracle db

时间:2016-08-04 13:13:07

标签: spring-boot bitronix

我已将bitronix配置如下:

   <bean id="bitronixTMConfig" factory-method="getConfiguration" class="bitronix.tm.TransactionManagerServices">
         <!-- Disabling Jmx avoids registering JMX Beans to any container -->
         <!-- <property name="disableJmx" value="true" /> -->
         <property name="serverId" value="request-handler-node" />
         <property name="defaultTransactionTimeout" value="300" />
         <!-- <property name="logPart1Filename" value="C:\temp\bit-btm1.tlog" /> -->
         <!-- <property name="logPart2Filename" value="C:\temp\bit-btm2.tlog" /> -->
   </bean>

   <bean id="bitronixTM" factory-method="getTransactionManager" class="bitronix.tm.TransactionManagerServices" depends-on="bitronixTMConfig" />

   <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager" primary="true">
         <property name="transactionManager" ref="bitronixTM" />
         <property name="userTransaction" ref="bitronixTM" />
         <property name="allowCustomIsolationLevels" value="true" />
   </bean>

<bean id="applicationDataSource" class="bitronix.tm.resource.jdbc.PoolingDataSource" init-method="init" destroy-method="close">
         <property name="uniqueName" value="applicationDataSource" />
         <property name="className" value="oracle.jdbc.xa.client.OracleXADataSource" />
         <property name="minPoolSize" value="${requestHandlerNode.repository.app.minPoolSize}" />
         <property name="maxPoolSize" value="${requestHandlerNode.repository.app.maxPoolSize}" />
         <property name="testQuery" value="SELECT 1 FROM DUAL" />
         <property name="allowLocalTransactions" value="true" />
         <property name="driverProperties">
                <props>
                       <prop key="user">${requestHandlerNode.repository.app.username}</prop>
                       <prop key="password">${requestHandlerNode.repository.app.password}</prop>
                       <prop key="URL">${requestHandlerNode.repository.app.url}</prop>
                </props>
         </property>
   </bean>

和pom依赖项:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-batch</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jms</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jta-bitronix</artifactId>
    </dependency>
    <dependency>
        <groupId>javax.jms</groupId>
        <artifactId>jms-api</artifactId>
    </dependency>
    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>javax.transaction-api</artifactId>
    </dependency>
    <dependency>
        <groupId>org.codehaus.btm</groupId>
        <artifactId>btm</artifactId>
        <exclusions>
            <exclusion>
                <groupId>javax.transaction</groupId>
                <artifactId>jta</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>11.2.0</version>
    </dependency>
    <dependency>
        <groupId>weblogic</groupId>
        <artifactId>wlthint3client</artifactId>
        <version>12.2.1</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

但是在启动时我收到了这个错误:

Caused by: java.lang.IllegalStateException: cannot change the configuration while the transaction manager is running
at bitronix.tm.Configuration.checkNotStarted(Configuration.java:699) ~[btm-2.1.4.jar:2.1.4]
at bitronix.tm.Configuration.setLogPart1Filename(Configuration.java:166) ~[btm-2.1.4.jar:2.1.4]
at org.springframework.boot.autoconfigure.transaction.jta.BitronixJtaConfiguration.bitronixConfiguration(BitronixJtaConfiguration.java:69) ~[spring-boot-autoconfigure-1.3.7.RELEASE.jar:1.3.7.RELEASE]
at org.springframework.boot.autoconfigure.transaction.jta.BitronixJtaConfiguration$$EnhancerBySpringCGLIB$$a487082a.CGLIB$bitronixConfiguration$1(<generated>) ~[spring-boot-autoconfigure-1.3.7.RELEASE.jar:1.3.7.RELEASE]
at org.springframework.boot.autoconfigure.transaction.jta.BitronixJtaConfiguration$$EnhancerBySpringCGLIB$$a487082a$$FastClassBySpringCGLIB$$c66fa53d.invoke(<generated>) ~[spring-boot-autoconfigure-1.3.7.RELEASE.jar:1.3.7.RELEASE]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:355) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.boot.autoconfigure.transaction.jta.BitronixJtaConfiguration$$EnhancerBySpringCGLIB$$a487082a.bitronixConfiguration(<generated>) ~[spring-boot-autoconfigure-1.3.7.RELEASE.jar:1.3.7.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_77]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_77]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_77]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_77]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
... 19 common frames omitted

我认为异常是由于spring boot和我的应用程序都初始化了bitronix transactionManager。

如何使用spring boot正确配置bitronix?

感谢您的帮助。

0 个答案:

没有答案