2015-10-13 55 views
2

我有一個春天啓動的應用程序作爲一個Spring JMS監聽器。我爲Oracle配置了多個數據源管理器,另一個配置了DB2。禁用事務管理可以在Spring的JMS的監聽

無論何時我開始應用程序,jms listener容器正在尋找一個事務管理器bean並在發現兩個bean時給出下面的錯誤。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jms.JmsAnnotationDrivenConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.transaction.PlatformTransactionManager org.springframework.boot.autoconfigure.jms.JmsAnnotationDrivenConfiguration.transactionManager; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.transaction.PlatformTransactionManager] is defined: expected single matching bean but found 2: db2TransactionManager,oracleTransactionManager 

我不想維護JMS事務。我怎麼能實現它,或者我們如何禁用jms事務功能?下面

是我對我的主彈簧引導類添加註釋。還我使用春數據倉庫

@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class, 
     DataSourceTransactionManagerAutoConfiguration.class}) 
@ComponentScan(basePackages = "com.deere.oracledataupdate.*") 
//@EnableJpaRepositories(basePackages ="com.deere.oracledataupdate.dao.springdata") 
@EntityScan(basePackages = "com.deere.oracledataupdate.*") 
@PropertySource({ "classpath:application-${IafConfigSuffix}.properties" }) 

public class Application extends SpringBootServletInitializer { 

public static void main(String[] args) { 

     SpringApplication.run(Application.class, args); 
    } 
} 
+0

您使用哪種彈簧啓動版本。 –

+0

我正在使用1.2.3.RELEASE的春季啓動 –

+1

更新到最新的1.2.6 ...早期版本的JMS自動配置依賴於PlatformTransactionManager新版本特定的JtaTransactionManager(通常)意識到在那裏進行交易。 –

回答

0

展望當前春季啓動代碼,我們有(JmsAnnotationDrivenConfiguration):

@Autowired(required = false) 
private JtaTransactionManager transactionManager; 

所以,現在只需要在bean這正是JtaTransactionManager的類型。我猜你們都是DataSourceTransactionManager

我敢肯定,這是正確的修復只擔心XA TXX管理器的自動配置。

對我來說,你可以在你的一個tx-manager bean上修復你的問題,如@Primary

但是...你需要在你的應用程序中的JMS註解支持呢?

也許它會剛好到排除JmsAnnotationDrivenConfiguration以及?

如果需要也無妨,我看到的只有一個辦法解決它:禁用JmsAnnotationDrivenConfiguration和手動配置@EnableJms,繞過TX-管理問題,併爲您的要求就是不將其配置爲DefaultJmsListenerContainerFactory

有關更多信息,請參閱JmsAnnotationDrivenConfiguration源代碼。

+0

嗨Artem,我剛剛將彈簧啓動版本更改爲最新版本,它停止給出該錯誤。在更改版本之前,我嘗試過提供像嘗試排除JmsAnnotationDrivenConfiguration一樣的建議,但是當我將此添加到@SpringBootApplication(exclude = {})時沒有JmsAnnotationDrivenConfiguration.class。如果你讓我知道如何像上面提到的那樣手動配置@EnableJms,或者共享一個示例鏈接,那就太好了。 –

+0

1.不確定爲什麼你沒有'JmsAnnotationDrivenConfiguration',因爲它是你上面的StackTrace的一部分。 2.請參閱Spring手冊關於'@ EnableJms':http://docs.spring.io/spring/docs/current/spring-framework-reference/html/jms.html#jms-annotated –