Simplified Spring transaction configuration in Jave ee 5

Source: Internet
Author: User
In the Java ee 5 Environment, spring configuration can greatly simplify the transaction configuration, which requires spring 2.0, such

Import org. springframework. transaction. annotation. Transactional;

@ Transactional
Public interface bookdao {

@ Transactional (readonly = true)
Book query (string ID );

@ Transactional (readonly = true)
List <book> queryall ();

Void insert (Book );

Void Update (book );

Void Delete (book );

}

Note that only public classes can be annotated, but not private classes,

In addition, the configuration in the XML file should be as follows:


xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
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/ SC Hema/Tx/spring-tx-2.0.xsd "

<Bean id = "datasource" class = "org. springframework. JDBC. datasource. drivermanagerdatasource">
<Property name = "driverclassname" value = "org. HSQLDB. jdbcdriver"/>
<Property name = "url" value = "JDBC: HSQLDB: Mem: Bookstore"/>
<Property name = "username" value = "sa"/>
<Property name = "password" value = ""/>
</Bean>

<! -- Define transactionmanager -->

<Bean id = "transactionmanager" class = "org. springframework. JDBC. datasource. cetcetransactionmanager">
<Property name = "datasource" ref = "datasource"/>
</Bean>

<! -- Define bookdao -->

<Bean id = "bookdao" class = "example. chapter6.bookdaoimpl">
<Property name = "datasource" ref = "datasource"/>
</Bean>

<! -- Automatically configure all beans with @ transactional annotation as declarative transaction support -->
<TX: annotation-driven transaction-Manager = "transactionmanager"/>

</Beans>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.