2016-08-04 88 views
0

我已經配置bitronix連接oracle數據庫如下:配置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 

我想這個例外是由於春季啓動和我的應用程序這兩個事實初始化bitronix transactionManager。

如何正確配置帶彈簧引導的Bitronix?

感謝您的幫助。

+0

那麼不要...... Spring Boot已經爲您做了所有這些工作,而不是針對它的框架。 –

+0

好的,謝謝,但我怎麼能配置數據源屬性,用戶名,密碼,url,classname和其他屬性,連接Oracle數據庫? –

+0

您正在使用Spring Boot等技術,您是否花時間閱讀手冊?只需配置正確的'spring.datasource。*'屬性,如'username','password'和'url'。 –

回答

0

我有另一個問題... 我配置了bitronix的spring-boot並添加了spring-batch。

我運行作業和所有工作正常,但是當調度程序重新啓動作業,我收到以下異常:

bitronix.tm.resource.ResourceConfigurationException: cannot create JDBC datasource named dataSource 
     at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:245) 
     at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373) 
     at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:427) 
     at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:276) 
     at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) 
     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
     at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208) 
     at com.sun.proxy.$Proxy61.getLastJobExecution(Unknown Source) 
     at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:98) 
     at com.enel.twobeat.dlnsadapter.responsehandlernode.scheduler.AutoScheduler.run(AutoScheduler.java:37) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
     at java.lang.reflect.Method.invoke(Method.java:498) 
     at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65) 
     at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) 
     at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81) 
     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) 
     at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) 
     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
     at java.lang.Thread.run(Thread.java:745) 
Caused by: bitronix.tm.resource.ResourceConfigurationException: cannot create JDBC datasource named dataSource 
     at bitronix.tm.resource.jdbc.PoolingDataSource.init(PoolingDataSource.java:92) 
     at org.springframework.boot.jta.bitronix.PoolingDataSourceBean.init(PoolingDataSourceBean.java:70) 
     at bitronix.tm.resource.jdbc.PoolingDataSource.getConnection(PoolingDataSource.java:250) 
     at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:204) 
     ... 23 more 
Caused by: java.lang.IllegalArgumentException: resource with uniqueName 'dataSource' has already been registered 
     at bitronix.tm.resource.ResourceRegistrar.register(ResourceRegistrar.java:83) 
     at bitronix.tm.resource.jdbc.PoolingDataSource.buildXAPool(PoolingDataSource.java:104) 
     at bitronix.tm.resource.jdbc.PoolingDataSource.init(PoolingDataSource.java:88) 
     ... 26 more 

好像彈簧批試着重新誰已創建的數據源。我該如何解決這個問題?

非常感謝