我似乎对 spring 注释驱动的事务管理和 tomcat 有问题。 这些是我在我的项目中使用的一些 bean:
<bean id="dataSource" class="service.myBatis.RoutingDataSource"> </bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
当我在 eclipse 中运行项目时,一切正常。但是当我在 tomcat 中运行该项目时,它并没有通过 bean 的创建。它也不会给我一个错误或任何错误的指示。
日志显示它完成了一个 bean 的实例化,然后它突然销毁了所有 bean:
[DEBUG] 12 jul 09:28:55.888 AM localhost-startStop-1 [org.springframework.beans.factory.support.DefaultListableBeanFactory]
Finished creating instance of bean 'org.springframework.transaction.config.internalTransactionAdvisor'
[INFO] 12 jul 09:28:55.895 AM localhost-startStop-1 [org.springframework.beans.factory.support.DefaultListableBeanFactory]
Destroying singletons in........
如果我删除 <tx:annotation-driven transaction-manager="transactionManager" />
该项目将在 tomcat 和 eclipse 中正常启动。
通常,如果某些东西在 eclipse 中有效而在 tomcat 中无效,这是由于 tomcat 没有找到某些类/库或资源造成的。我不知道是什么原因造成的
谁能告诉我问题出在哪里?为什么它会在不报错的情况下销毁所有 bean?
最佳答案
我想通了。导致问题的不是 Spring ,而是我项目中的其他问题。错误被放入一些 tomcat 日志而不是控制台。所以看起来没有错误。
关于Spring tx :annotation-driven works in eclipse, 但不在 tomcat 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11448071/