I absolutely agree with you haninaguib, though I'm not sure why you would think I would want it any other way.
Maybe an example clarifies what I exactly mean :
applicationContext.xml
Code:
<bean id="myBusinessObject" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager"><ref bean="myTransactionManager"/></property>
...
</bean>
dataAccessContext-local.xml
Code:
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
...
</bean>
<bean id="anotherDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
... // pointing to another DB server
</bean>
<bean id="myTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource"><ref local="myDataSource"/></property>
</bean>
test-beans.xml
Code:
<bean id="myTestBean" class="package.SpringTransactionTest">
<property name="businessObject"><ref bean="myBusinessObject"/></property>
</bean>
test class
Code:
protected String[] getConfigLocations() {
return new String[] {"applicationContext.xml", "dataAccessContext-local.xml", "test-beans.xml"};
}
So the test expects "myBusinessObject" injected, but runs into the exception mentioned earlier, stating I have to many beans of type javax.sql.DataSource. Which seems logical, because it's autowire by type.
So I can't use that approach, as the doc states. What I don't understand is that in such a case the doc states I should use the inherited (= depending on dependency injected dataSource) applicationContext instance, because the DI fails, hence I lose my capabilities of transaction managed testing ?
A possible solution, the approach of using a dedicated test context file for the test class means not reusing the dataAccessContext file if I want to make this work, but I simply wonder if there are better alternatives.
Thank you for answering in any case.