I got stuck last week because we have two DataSource beans with different names, for different databases. My AbstractTransactionalDataSourceSpringContextTests Unit Tests did not like this:
Unsatisfied dependency expressed through bean property 'dataSource': No unique bean of type [javax.sql.DataSource] is defined: expected single matching bean but found 2
The problem is that by default AbstractTransactionalDataSourceSpringContextTests is set to autowire by type. I changed this to autowire by name, in the getConfigLocations method:
protected String[] getConfigLocations(){ setAutowireMode(AUTOWIRE_BY_NAME); return new String[]{ "test-applicationContext.xml" }; }
To get the Daos I was testing injected, all I had to do was create getters and setters with the same names as I had specified for for the Dao beans in my applicationContext. So little to do!
Thx, I have search during 2hours, and I have found my problem with your help!
Please can you send sample test-applicationContext.xml and code
Hi, Sorry I don’t have a simple example I can send :(
Thanks! A simple search for “AbstractTransactionalDataSourceSpringContextTests autowire by name” and your post came tops. Just what I needed. :-)