开发者

how to use transaction manager in spring 3

i tried using this in spring 3 xml file but it gives error

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

what thinga are req开发者_如何转开发uired for this to work


You need a transactionManager, e.g.,

<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):

<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.


you need to add cglib-nodep-2.1_3.jar aopalliance-1.0.jar to your classpath and add xmlns:tx="http://www.springframework.org/schema/tx to your applicationContext.xml definition

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜