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驱动。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
<!-- 数据源配置 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驱动,推荐此配置,可以配置连接池的信息。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
<!-- 数据源配置 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的驱动,可以配置连接池:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
<!-- 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> |
本文介绍到此结束@Michael Sun.
原创文章,转载请注明: 转载自micmiu – 软件开发+生活点滴[ http://www.micmiu.com/ ]
本文链接地址: http://www.micmiu.com/j2ee/jta/atomikos-datasource-cfg/
没有一个是全乎的,你的class属性呢?
本文中没有你说的什么class属性 这个内容,无法回答你这个问题
哥们,你确实没有配bean的class