I'm trying to run an junit test with JTA outside of a jee container.
I have two datasources in my XXX-context.xml
<bean id="datasource1" class="com.atomikos.jdbc.SimpleDataSourceBean" init-method="init" destroy-method="close">
<property name="uniqueResourceName"><value>${jdbc.datasource 1}</value></property>
<property name="xaDataSourceClassName"><value>${jdbc.driverC lassName}</value></property>
<property name="xaDataSourceProperties">
...
</property>
....
</bean>
<bean id="sessionFactory1" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean"
p:dataSource-ref="datasource1">
...
<prop key="hibernate.transaction.factory_class">org.hibe rnate.transaction.JTATransactionFactory</prop>
<prop key="hibernate.transaction.manager_lookup_class">c om.atomikos.icatch.jta.hibernate3.TransactionManag erLookup</prop>
</bean>
and the same for the second data source (datasource2) and session factory.
I'm extending the AbstractTransactionalJUnit4SpringContextTests and when I try to run it I get the following exception :
org.springframework.beans.factory.BeanCreationExce ption: Could not autowire method: public void org.springframework.test.context.junit4.AbstractTr ansactionalJUnit4SpringContextTests.setDataSource( javax.sql.DataSource);
nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No unique bean of type [javax.sql.DataSource] is defined:
expected single matching bean but found 2: [datasource1, datasource2]
The problem looks to be that the method public void setDataSource(final DataSource dataSource) in the class AbstractTransactionalJUnit4SpringContextTests is
annotated with @Autowired.
Any idea about how could I solve this ?
Thanks.
--
K 4 |v| 4


Reply With Quote