简体   繁体   English

在春季3中如何使用事务管理器

[英]how to use transaction manager in spring 3

i tried using this in spring 3 xml file but it gives error 我试过在Spring 3 xml文件中使用它,但是它给出了错误

<tx:annotation-driven transaction-manager="transactionManager" />

what thinga are required for this to work 工作需要什么东西

You need a transactionManager, eg, 您需要一个transactionManager,例如

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

Which requires a SessionFactory which in turn requires a DataSource (here c3p0): 它需要一个SessionFactory,而后者又需要一个DataSource(在此为c3p0):

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
  <property name="dataSource" ref="dataSource" />   
  ... 
</bean>

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
   ...
</bean>

You also need to declare your transactions. 您还需要声明您的交易。 I personally prefer the declarative transaction approach where you simply annotate your database routines with @Transactional . 我个人更喜欢声明式事务处理方法,在该方法中,您只需使用@Transactional注释数据库例程。

您需要将cglib-nodep-2.1_3.jar aopalliance-1.0.jar添加到您的类路径中,并将xmlns:tx =“ http://www.springframework.org/schema/tx添加到applicationContext.xml定义中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM