Announcement Announcement Module
No announcement yet.
AbstractTranDataSrcSpringContextTests finds two beans. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • AbstractTranDataSrcSpringContextTests finds two beans.

    Hi folks.

    I'm sure I've done something silly, but just can't figure it out. I added transaction management to my configuration this morning and started working on some integration tests using AbstractTransactionalDataSourceSpringContextTests as a base class. The problem is that when the test runs, I get an UnsatisfiedDependencyException because it finds two beans that match the interface type. The first bean is my implementation bean. The second is the TransactionProxyFactoryBean that wraps my implementation in a transaction.

    So, my question is pretty straightforward, I hope. How can I get the autowire by type of the test framework to get along with the Transaction proxy? I don't see how I can define both my implementation bean and the proxy without having two beans of the same type in the context.


  • #2

    Hi Dave,

    The AbstractTransactionalDataSourceSpringContextTests is an indirect subclass of AbstractDependencyInjectionSpringContextTests. You can change the autowire mode via the setAutowireMode method. Maybe you can try AbstractDependencyInjectionSpringContextTests.AUTO WIRE_BY_NAME.

    Also, if you define the target (non-transactional) bean as an inner bean (which is recommended in many Spring books whenever possible), you won't have two beans of that type.


    • #3
      Thanks, Arthur. I had completely forgotten about using inner beans. That did the trick.

      Now, apparently the AbstractTransactionalDataSourceContextTests isn't rolling back the transaction after my test, but I haven't really looked into it closely yet.

      Thanks again.