我测试从JBoss AS 7.0.1到Wild Fly 8.2.0 final的迁移。 原因:log4j错误导致数据库死锁;只在JBoss EAP中解决的bug我无法使用=>然后Wild Fly似乎是一个很好的候选人
我正在使用 XA数据源与 JTA事务管理器
JBoss AS 7.x和Wild Fly 8.2.x之间的配置(standalone.xml)似乎相同:
数据来源1
<datasource jta="true" jndi-name="java:/DS_Habilitation" pool-name="DS_Habilitation" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:sqlserver://localhost:1433;instanceName=*****;databaseName=Habilitations_DV</connection-url>
<driver>sqlserver</driver>
<pool>
<min-pool-size>10</min-pool-size>
<max-pool-size>100</max-pool-size>
<prefill>true</prefill>
<use-strict-min>false</use-strict-min>
<flush-strategy>FailingConnectionOnly</flush-strategy>
</pool>
<security>
<user-name>*****</user-name>
<password>*******</password>
</security>
</datasource>
数据源2
<datasource jta="true" jndi-name="java:/DS_Referentiel" pool-name="DS_Referentiel" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:sqlserver://localhost:1433;instanceName=*****;databaseName=Referentiel_DV</connection-url>
<driver>sqlserver</driver>
<pool>
<min-pool-size>10</min-pool-size>
<max-pool-size>100</max-pool-size>
<prefill>true</prefill>
<use-strict-min>false</use-strict-min>
<flush-strategy>FailingConnectionOnly</flush-strategy>
</pool>
<security>
<user-name>*****</user-name>
<password>******</password>
</security>
</datasource>
数据源3
<datasource jta="true" jndi-name="java:/DS_Sinistre" pool-name="DS_Sinistre" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:sqlserver://localhost:1433;instanceName=****;databaseName=Sinistres_DV</connection-url>
<driver>sqlserver</driver>
<pool>
<min-pool-size>10</min-pool-size>
<max-pool-size>100</max-pool-size>
<prefill>true</prefill>
<use-strict-min>false</use-strict-min>
<flush-strategy>FailingConnectionOnly</flush-strategy>
</pool>
<security>
<user-name>******</user-name>
<password>******</password>
</security>
</datasource>
我启动Wild Fly并正确部署我的WAR 当我登录时,我调用2个数据源,我有错误:
ARJUNA012140: Adding multiple last resources is disallowed. Trying to add LastResourceRecord(XAOnePhaseResource
我通过添加“Wild Fly”服务器conf文件standalone.xml解决了这个问题:
<system-properties>
<property name="com.arjuna.ats.arjuna.allowMultipleLastResources" value="true"/>
</system-properties>
然后我有警告表明我的交易不安全,因为我有多个数据源
WARN [com.arjuna.ats.arjuna] (default task-27) ARJUNA012141: Multiple last resources have been added to the current transaction. This is transactionally unsafe and should not be relied upon. Current resource is LastResourceRecord(XAOnePhaseResource(
有关信息,我的服务是这样的(1次转换)
@Service("gestionnaireService") @Transactional(value="transactionManager")
public class GestionnaireServiceImpl implements GestionnaireService {
@Autowired
private UtilisateurService utilisateurService;
@Autowired
private GestionnaireDao gestionnaireDao;
.....
}
数据源如下:
<bean id="dataSourceReferentiel" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:/DS_Referentiel" />
</bean>
...
<bean id="sessionFactoryReferentiel" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSourceReferentiel" />
<property name="mappingResources">
<list>
<value>hibernate/referentiel/DonneeReference.hbm.xml</value>
<value>hibernate/referentiel/LibelleReference.hbm.xml</value>
<value>hibernate/referentiel/Localite.hbm.xml</value>
<value>hibernate/referentiel/Banque.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.generate_statistics">false</prop>
<prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</prop>
<prop key="hibernate.show_sql">false</prop>
<!-- <prop key="transaction.flush_before_completion">true</prop>-->
<prop key="hibernate.cache.use_query_cache">true</prop>
<!-- Level 2 cache -->
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.region.factory_class" >org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory</prop>
</props>
</property>
</bean>
...
<!-- Transaction manager -->
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
第一点是JBoss AS7我没有这个问题我应该有
第二,我想知道我的数据源是否配置正确(XA)或是否是我的服务......
你能就此给我意见吗?
由于
答案 0 :(得分:1)
@Service @Transactional(value="transactionManager", propagation=Propagation.REQUIRES_NEW)
public class ReferenceServiceImpl implements ReferenceService {
@Autowired
private ReferenceDao dao;
...
}
我已经测试过,如果在此过程中失败,所有交易都会被回滚:很好
我最后的反思是我真的需要设置XA数据源。我使用相同的数据库实例分隔我的模式。不知道有一天我们会在不同的机器上设置shemas。
无论如何,我想感谢这个社区提供的帮助。