oracle驱动升级后,Atomikos数据源配置方式。
上午把oracle 驱动升级为 ojdbc14-11.2.0后,项目启动时报错:
15:56:00.827 [main] WARN atomikos - ERROR IN RECOVERY com.atomikos.datasource.ResourceException: Error in recovery at com.atomikos.datasource.xa.XATransactionalResource.recover(XATransactionalResource.java:596) at com.atomikos.datasource.xa.XATransactionalResource.endRecovery(XATransactionalResource.java:670) at com.atomikos.icatch.imp.TransactionServiceImp.recover(TransactionServiceImp.java:635) at com.atomikos.datasource.xa.XATransactionalResource.setRecoveryService(XATransactionalResource.java:503) at com.atomikos.icatch.system.Configuration.installRecoveryService(Configuration.java:278) at com.atomikos.icatch.imp.TransactionServiceImp.recover(TransactionServiceImp.java:580) at com.atomikos.icatch.imp.TransactionServiceImp.init(TransactionServiceImp.java:741) at com.atomikos.icatch.imp.BaseTransactionManager.init(BaseTransactionManager.java:217) at com.atomikos.icatch.standalone.StandAloneTransactionManager.init(StandAloneTransactionManager.java:104) at com.atomikos.icatch.standalone.UserTransactionServiceImp.init(UserTransactionServiceImp.java:307) at com.atomikos.icatch.config.UserTransactionServiceImp.init(UserTransactionServiceImp.java:413) at com.atomikos.icatch.jta.UserTransactionManager.checkSetup(UserTransactionManager.java:90) at com.atomikos.icatch.jta.UserTransactionManager.init(UserTransactionManager.java:140) 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)
解决方式:将之前的AtomikosDataSourceBean配置方式换为AtomikosNonXADataSourceBean方式。
<!-- 配置dataSource数据源 --> <bean id="parentDataSource" class="com.atomikos.jdbc.nonxa.AtomikosNonXADataSourceBean" init-method="init" destroy-method="close" p:uniqueResourceName="rw1" p:testQuery="select 1 from dual" abstract="true"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /> <property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:ORCL" /> <property name="user" value="TEST_RW_1" /> <property name="password" value="TEST_RW_1" /> <property name="poolSize" value="5" /> <property name="maxPoolSize" value="30" /> </bean> <bean id="com.fand.dataSource.rw1" parent="parentDataSource"></bean> <bean id="com.fand.dataSource.rw2" p:uniqueResourceName="rw2" parent="parentDataSource"> <property name="user" value="TEST_RW_2" /> <property name="password" value="TEST_RW_2" /> </bean> <bean id="com.fand.dataSource.rw3" p:uniqueResourceName="rw3" parent="parentDataSource"> <property name="user" value="TEST_RW_3" /> <property name="password" value="TEST_RW_3" /> </bean> <bean id="com.fand.dataSource.rw4" p:uniqueResourceName="rw4" parent="parentDataSource"> <property name="user" value="TEST_RW_4" /> <property name="password" value="TEST_RW_4" /> </bean> <bean id="com.fand.dataSource.r1" p:uniqueResourceName="r1" parent="parentDataSource"> <property name="user" value="TEST_R_1" /> <property name="password" value="TEST_R_1" /> </bean> <bean id="com.fand.dataSource.r2" p:uniqueResourceName="r2" parent="parentDataSource"> <property name="user" value="TEST_R_2" /> <property name="password" value="TEST_R_2" /> </bean> <bean id="com.fand.dataSource.r3" p:uniqueResourceName="r3" parent="parentDataSource"> <property name="user" value="TEST_R_3" /> <property name="password" value="TEST_R_3" /> </bean> <bean id="com.fand.dataSource.r4" p:uniqueResourceName="r4" parent="parentDataSource"> <property name="user" value="TEST_R_4" /> <property name="password" value="TEST_R_4" /> </bean> <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="transactionManager"> <bean class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close"> <property name="forceShutdown" value="true" /> </bean> </property> <property name="userTransaction"> <bean class="com.atomikos.icatch.jta.UserTransactionImp" p:transactionTimeout="6000" /> </property> <property name="allowCustomIsolationLevels" value="true" /> </bean> <tx:annotation-driven />
Atomikos数据源配置方法有三种分别:
- SimpleDataSourceBean
- AtomikosDataSourceBean
- AtomikosNonXADataSourceBean
下面的演示以Orcale数据库为例子
- 数据源1:192.168.8.1 sid:orcl 用户名/密码:micmiu/micmiu.com
- 数据源2:192.168.8.2 sid:orcl 用户名/密码:ctosun/ctosun.com
[一]、SimpleDataSourceBean
这个是最简单地数据源配置,需要配置XA驱动。
<!-- 数据源配置 simple 1 --> <bean id="simpleDS1" init-method="init" destroy-method="close"> <property name="uniqueResourceName"> <!-- 该值要唯一 --> <value>simpleDS1</value> </property> <property name="xaDataSourceClassName"> <value>oracle.jdbc.xa.client.OracleXADataSource</value> </property> <property name="xaDataSourceProperties"> <value>URL=jdbc:oracle:thin:@192.168.8.1:1521:orcl;user=micmiu;password=micmiu.com </value> </property> <property name="exclusiveConnectionMode"> <value>true</value> </property> <property name="connectionPoolSize"> <value>3</value> </property> <property name="validatingQuery"> <value>SELECT 1 from dual</value> </property> </bean> <!-- 数据源配置 simple 2 --> <bean id="simpleDS2" init-method="init" destroy-method="close"> <property name="uniqueResourceName"> <value>simpleDS2</value> </property> <property name="xaDataSourceClassName"> <value>oracle.jdbc.xa.client.OracleXADataSource</value> </property> <property name="xaDataSourceProperties"> <value>URL=jdbc:oracle:thin:@192.168.8.2:1521:orcl;user=ctosun;password=ctosun.com </value> </property> <property name="exclusiveConnectionMode"> <value>true</value> </property> <property name="connectionPoolSize"> <value>3</value> </property> <property name="validatingQuery"> <value>SELECT 1 from dual</value> </property> </bean>
[二]、AtomikosDataSourceBean
Atomikos实现的数据源,需要配置XA驱动,推荐此配置,可以配置连接池的信息。
<!-- 数据源配置 Atomikos datasource 1 --> <bean id="atomikosDS1" init-method="init" destroy-method="close"> <property name="uniqueResourceName"> <!-- 该值要唯一 --> <value>atomikosDS1</value> </property> <property name="xaDataSourceClassName"> <value>oracle.jdbc.xa.client.OracleXADataSource</value> </property> <property name="xaProperties"> <props> <prop key="URL">jdbc:oracle:thin:@192.168.8.1:1521:orcl</prop> <prop key="user">micmiu</prop> <prop key="password">micmiu.com</prop> </props> </property> <property name="poolSize"> <value>5</value> </property> <property name="maxPoolSize"> <value>15</value> </property> </bean> <!-- 数据源配置 Atomikos datasource 2 --> <bean id="atomikosDS2" init-method="init" destroy-method="close"> <property name="uniqueResourceName"> <!-- 该值要唯一 --> <value>atomikosDS2</value> </property> <property name="xaDataSourceClassName"> <value>oracle.jdbc.xa.client.OracleXADataSource</value> </property> <property name="xaProperties"> <props> <prop key="URL">jdbc:oracle:thin:@192.168.8.2:1521:orcl</prop> <prop key="user">ctosun</prop> <prop key="password">ctosun.com</prop> </props> </property> <property name="poolSize"> <value>5</value> </property> <property name="maxPoolSize"> <value>15</value> </property> </bean>
[三]、AtomikosNonXADataSourceBean
该数据源配置需要普通JDBC的驱动,可以配置连接池:
<!-- AtomikosNonXA datasource 1 需要普通jdbc驱动 --> <bean id="atomikosNonXADS1"> <property name="uniqueResourceName"> <value>atomikosNonXADS1</value> </property> <property name="driverClassName"> <value>oracle.jdbc.driver.OracleDriver</value> </property> <property name="url"> <value>jdbc:oracle:thin:@192.168.8.1:1521:orcl</value> </property> <property name="user"> <value>micmiu</value> </property> <property name="password"> <value>micmiu.com</value> </property> <property name="poolSize"> <value>5</value> </property> <property name="borrowConnectionTimeout"> <value>60</value> </property> </bean> <!-- AtomikosNonXA datasource 2 需要普通jdbc驱动 --> <bean id="atomikosNonXADS2"> <property name="uniqueResourceName"> <value>atomikosNonXADS2</value> </property> <property name="driverClassName"> <value>oracle.jdbc.driver.OracleDriver</value> </property> <property name="url"> <value>jdbc:oracle:thin:@192.168.8.2:1521:orcl</value> </property> <property name="user"> <value>ctosun</value> </property> <property name="password"> <value>ctosun.com</value> </property> <property name="poolSize"> <value>5</value> </property> <property name="borrowConnectionTimeout"> <value>60</value> </property> </bean>
相关推荐
yangkang 2020-11-09
lbyd0 2020-11-17
sushuanglei 2020-11-12
85477104 2020-11-17
KANSYOUKYOU 2020-11-16
wushengyong 2020-10-28
lizhengjava 2020-11-13
星月情缘 2020-11-13
huangxiaoyun00 2020-11-13
luyong0 2020-11-08
腾讯soso团队 2020-11-06
Apsaravod 2020-11-05
PeterChangyb 2020-11-05
gaobudong 2020-11-04
wwwjun 2020-11-02
gyunwh 2020-11-02
EchoYY 2020-10-31
dingyahui 2020-10-30