Spring Framework Declarative Transaction with Annotations

<tx:annotation-driven transaction-manager=”txManager”/> where txManager points the underlying transaction manager and the tx namespace refers to http://www.springframework.org/schema/tx

<!– the service class that we want to make transactional –>

@Transactional

public class DangerousService implements NightmareService {

Foo getFoo(String fooName){ … }

Foo getFoo(String fooName, String barName) { … }

void insertDangerousObject(DangerousObject foo) {…}

void updateDangerousObject(DangerousObject foo) {…}

}

<!– from the file ’spring applicationcontext.xml’ –>

<?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:aop=”http://www.springframework.org/schema/aop”
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.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd”>

<!– this is the service object that we want to make transactional –>
<bean id=”dangerousService” class=”x.y.service.DangerousService”/>

<!– enable the configuration of transactional behavior based on annotations –>
<tx:annotation-driven transaction-manager=”txManager”/>

<!– a PlatformTransactionManager is still required –>

<bean id=”txManager” class=”org.springframework.jdbc.datasource.DataSourceTransactionManager”>

<!– (this dependency is defined somewhere else) –>

<property name=”dataSource” ref=”dataSource”/>
</bean>
<!– other <bean/> definitions here –>

</beans>

Written by Ravi Nallakukkala on April 10th, 2007 with no comments.
Read more articles on Spring.

Related articles

No comments

There are still no comments on this article.

Leave your comment...

If you want to leave your comment on this article, simply fill out the next form:




You can use these XHTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong> .