Spring and Ibatis Integration

Source: Internet
Author: User

Spring provides good support for Ibatis through DAO mode. The Sqlmapclient object is the primary object in Ibatis, and we can configure it to let Spring manage the creation of Sqlmapclient objects.

Like Hibernate, Spring provides a Sqlmapclientdaosupport object, and our DAO can inherit this class and manipulate the database through the Sqlmapclienttemplate object it provides. It seems that these concepts are similar to hibernate.

There is no problem in manipulating the database's crud through Sqlmapclienttemplate, and the key issue here is transaction processing. Spring provides powerful declarative transactional capabilities, and we already know how to configure declarative transactions in Hibernate, so how can we get declarative transactions in Ibatis?

First, we need to understand that Spring uses AOP to intercept the invocation of methods, thus adding declarative transactional capabilities to these methods. The typical configuration is as follows: Applicationcontext-common.xml


These transactions are declared on the object of the business logic layer.

Second, we need a transaction manager to manage the transaction.

Thereafter, we need to let spring manage the Sqlmapclient object:

Our sqlmapconfig.xml can be abbreviated as:

User.xml: The following:

The writing of my DAO:

Inheriting the sqlmapclientdaosupport requires us to inject the Sqlmapclient object, so the following DAO configuration is required:

That's all you need to be aware of, and then you can invoke the DAO object at the business logic level!

Spring and Ibatis Integration

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.