我有一个简单的 java 应用程序,它使用 spring 2.5.5 和 hiberate 3.3.1.GA。换句话说,它不在任何容器中运行,例如 tomcat 或 jboss。
我想通过使用注释@Tranactional 在应用程序中启用事务控制。然而,经过多次试验,应用程序并没有像我预期的那样开始任何交易。 (检查服务器端,sybase 12.5,使用sp_transactions
)
我已阅读doco几次,希望我没有错过任何东西。
我添加了 <tx:annotation-driven transaction-manager="txManager" />
到包含需要参与事务的 bean 的应用程序上下文 xml 文件。
谁能推荐一下
1) 我如何转向 spring 日志记录以了解 spring 框架如何发现和检测 @Transactional java 类?
2) 我正在使用 org.springframework.orm.hibernate3.HibernateTransactionManager
作为交易经理。是否正确?
3) 我是否需要添加任何 jar 来启用此支持?
这里是相关applicationContext.xml的部分 list
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"
default-lazy-init="false">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>com.sybase.jdbc3.jdbc.SybDriver</value>
</property>
<property name="url">
<value>${jdbc.connection.url}</value>
</property>
<property name="username">
<value>${jdbc.user}</value>
</property>
<property name="password">
<value>${jdbc.password}</value>
</property>
<property name="maxWait">
<value>30000</value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration
</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SybaseDialect
</prop>
<prop key="hibernate.jdbc.batch_size">
50
</prop>
<prop key="show_sql">true</prop>
<prop key="hibernate.cache.provider_class">
org.hibernate.cache.EhCacheProvider
</prop>
<prop key="hibernate.cache.provider_configuration_file_resource_path">
ehcache.xml
</prop>
<prop key="hibernate.cache.use_query_cache">
true
</prop>
<prop key="hibernate.cache.use_second_level_cache">
true
</prop>
</props>
</property>
</bean>
<bean id="hibernateInterceptor" class="org.springframework.orm.hibernate3.HibernateInterceptor">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
编辑:
如果它是相关的(Spring @Transactional concurrency),我已经自由地使用@Transactional
最佳答案
- 将 org.springframework.transaction 的记录器设置为 DEBUG
- 视情况而定,如果您在真正的 J2EE 服务器(WAS、JBoss 等)上运行,那么您应该使用提供的事务管理器;如果不是(tomcat,jetty)你很好
- Javax transaction但是如果你使用 maven 和 hibernate 你应该已经有了它(因为 JTA 是一个 hibernate 依赖项)。如果您在 JBoss/WAS/...上部署,请不要部署此 jar,因为这可能会与他们提供的 JTA 发生冲突。
关于java - Spring + hibernate : how can I tell if spring has picked up all the @transactional annotation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8265174/