Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transaction configuration for Spring Java configured context

I've been struggling with this for a few hours now.

I'm trying to migrate my Spring XML configuration to a full Java based configuration.

I'm using AnnotationConfigApplicationContext as a context implementation.

I'm having trouble finding an Java equivalent for this line, from my old XML configuration:

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

As a result, Spring doesn't manage the transactions.

In my Java configuration I have initialized the relevant beans for transactions: the session factory, the transactional manager, etc, but without that line, no transaction proxy is used, so no transactions are actually in place.

So my question is how do I either translate that line to my Java context configuration or how to I go about solving the problem in another way.

Any help is appreciated. Thanks.

like image 314
Eugen Avatar asked Nov 09 '10 22:11

Eugen


People also ask

What is a transaction in the context of Spring data?

Transactions and Proxies. At a high level, Spring creates proxies for all the classes annotated with @Transactional, either on the class or on any of the methods. The proxy allows the framework to inject transactional logic before and after the running method, mainly for starting and committing the transaction.

What is use of @transactional annotation in Spring?

One of the most essential parts of Spring MVC is the @Transactional annotation, which provides broad support for transaction management and allows developers to concentrate on business logic rather than worrying about data integrity in the event of system failures.

What is @transactional annotation in Java?

Transactional annotation provides the application the ability to declaratively control transaction boundaries on CDI managed beans, as well as classes defined as managed beans by the Java EE specification, at both the class and method level where method level annotations override those at the class level.


1 Answers

You can now use @EnableTransactionManagement.

See: http://blog.springsource.com/2011/06/10/spring-3-1-m2-configuration-enhancements/

like image 172
AHungerArtist Avatar answered Oct 11 '22 03:10

AHungerArtist