问题描述
- 关于JBOSS AS7 多个数据源配置问题
-
我在JBOSS7的standalone.xml配置文件中配置了两个数据源,JAVA代理连接第一数据源能否正常连接,并能否正常访问到数据库的数据,但连接另外一个数据源时就报错,报错信息:ARJUNA012140: Adding multiple last resources is disallowed. Trying to add LastResourceRecord我使用的JDBC连接。
请各位大侠帮忙指点下,多个数据源在JBOSS7如何使用,谢谢!
具体配置和代码如下:
standalone.xml数据源配置:jdbc:oracle:thin:@134.111.9.81:1521:myoracle
oracleptkintf
abc_110jdbc:oracle:thin:@134.111.10.156:1521:feeoracle
oraclefeeintf
fee_intf_07657oracle.jdbc.OracleDriver
oracle.jdbc.xa.client.OracleXADataSourceJAVA代码:
public class MyEjb3LocalImpl implements MyEjb3Intf{
@Override
public String callMyejb3(String str) {
queryPTKDbTest();
queryFeeDbTest();
return "SUCCESS";
}private void queryPTKDbTest(){ Connection conn = null; Statement stmt = null; ResultSet rs = null; try{ DataSource dataSource = (DataSource)ContextUtil.getBean("java:jboss/datasources/PTKtestDS"); conn = dataSource.getConnection();; stmt = conn.createStatement(); String sql = "select t.province, t.area_name from area t where t.area_code = '0591'"; rs = stmt.executeQuery(sql); if(rs.next()){ System.out.println(rs.getString("province")); System.out.println(rs.getString("area_name")); } }catch(SQLException e){ e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); }finally{ if(rs != null){ try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if(stmt != null){ try { stmt.close(); } catch (SQLException e) { e.printStackTrace(); } } if(conn != null){ try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } } private void queryFeeDbTest(){ Connection conn = null; Statement stmt = null; ResultSet rs = null; try{ DataSource dataSource = (DataSource)ContextUtil.getBean("java:jboss/datasources/FeeDS"); conn = dataSource.getConnection();; stmt = conn.createStatement(); String sql = "select t.CZ_NBR, t.CZ_AMOUNT from bill_591.sms_notify t where t.CZ_TIME > (sysdate - 5/24/60/60)"; rs = stmt.executeQuery(sql); if(rs.next()){ System.out.println(rs.getString("CZ_NBR")); System.out.println(rs.getInt("CZ_AMOUNT")); } }catch(SQLException e){ e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); }finally{ if(rs != null){ try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if(stmt != null){ try { stmt.close(); } catch (SQLException e) { e.printStackTrace(); } } if(conn != null){ try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } }
报错信息:
09:46:30,107 WARN com.arjuna.ats.arjuna ARJUNA012140: Adding multiple last resources is disallowed. Trying to add LastResourceRecord(XAOnePhaseResource(LocalXAResourceImpl@3b96bb[connectionListener=1fe0dcb connectionManager=24e39f warned=false currentXid=< formatId=131077, gtrid_length=29, bqual_length=36, tx_uid=0:ffff8682fe53:-4a97a196:541b8af0:c, node_name=1, branch_uid=0:ffff8682fe53:-4a97a196:541b8af0:12, subordinatenodename=null, eis_name=unknown eis name >])), but already have LastResourceRecord(XAOnePhaseResource(LocalXAResourceImpl@ca677f[connectionListener=15c90f4 connectionManager=360733 warned=falsecurrentXid=< formatId=131077, gtrid_length=29, bqual_length=36, tx_uid=0:ffff8682fe53:-4a97a196:541b8af0:c, node_name=1, branch_uid=0:ffff8682fe53:-4a97a196:541b8af0:11, subordinatenodename=null, eis_name=unknown eis name >]))
09:46:30,123 ERROR stderr java.sql.SQLException: javax.resource.ResourceException: IJ000457: Unchecked throwable in managedConnectionReconnected() cl=org.jboss.jca.core.connectionmanager.listener.TxConnectionListener@1fe0dcb[state=NORMAL managed connection=org.jboss.jca.adapters.jdbc.local.LocalManagedConnection@1826710 connection handles=0 lastUse=1411091190123 trackByTx=false pool=org.jboss.jca.core.connectionmanager.pool.strategy.OnePool@3c8087 pool internal context=SemaphoreArrayListManagedConnectionPool@eec35c[pool=FeeDS] xaResource=LocalXAResourceImpl@3b96bb[connectionListener=1fe0dcb connectionManager=24e39f warned=false currentXid=null] txSync=null]
09:46:30,123 ERROR stderr at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:137)
09:46:30,123 ERROR stderr at com.ptk.impl.MyEjb3LocalImpl.queryFeeDbTest(MyEjb3LocalImpl.java:75)
09:46:30,123 ERROR stderr at com.ptk.impl.MyEjb3LocalImpl.callMyejb3(MyEjb3LocalImpl.java:21)
09:46:30,123 ERROR stderr at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
09:46:30,123 ERROR stderr at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
09:46:30,123 ERROR stderr at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
09:46:30,123 ERROR stderr at java.lang.reflect.Method.invoke(Method.java:597)
09:46:30,123 ERROR stderr at org.jboss.as.ee.component.ManagedReferenceMethodInterceptorFactory$ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptorFactory.java:72)
09:46:30,123 ERROR stderr at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
09:46:30,123 ERROR stderr at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
09:46:30,123 ERROR stderr at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:36)
解决方案
贴出来的东西乱七八糟的,也不整理一下,懒得回答