我使用@Configuration
註釋來配置spring,而不是xml文件。我使用不同的會話工廠和不同的事務管理器配置2個數據源。我在這裏爲@EnableTransactionManagement
註解卡住了問題。我的文檔是,@EnableTransactionManagement帶2個事務管理器的註釋
@EnableTransactionManagement
is more flexible; it will fall back to a by-type lookup for anyPlatformTransactionManager
bean in the container. Thus the name can be "txManager", "transactionManager", or "tm": it simply does not matter.
這意味着我給方法的任何名稱,它總是會尋找,而我有2個事務管理器返回PlatformTransactionManager
對象的方法讀取。現在的問題是,當我測試這個類,它給我的錯誤:
org.springframework.beans.factory.NoSuchBeanDefinitionException
: No unique bean of type [org.springframework.transaction.PlatformTransactionManager
] is defined: expected single bean but found 2
我什至有2個不同的配置類,但徒勞無功。在xml配置中,情況並非如此。我給兩位交易經理註冊了兩個<tx:annotation-driven transaction-manager="" />
標籤,它工作正常。但不能在這裏做註釋。
如果我想在Spring註釋的配置類中使用2個不同的事務管理器配置2個數據源,應該怎麼做?
這可能是一個bug,因爲Spring 3.1仍處於beta/rc階段。 – skaffman