When using spring mvc, I used an annotation such as @ Service and found that the transactions declared by @ Transactional are not

Source: Internet
Author: User

Scenario:

When using spring mvc, I used an annotation such as @ Service and found that the transaction declared by @ Transactional does not work.

My configuration is as follows:

<Mvc: annotation-driven/>

<Context: component-scan base-package = "org. test"/>

<Bean id = "txManager" class = "org. springframework. jdbc. datasource. cetcetransactionmanager">
<Property name = "dataSource" ref = "dataSource"/>
</Bean>

<Tx: annotation-driven transaction-manager = "txManager"/>

The reason is::

The context of component-scan is different from that of the transaction. The configuration of component-scan is loaded by servlet, And the configuration file of the transaction is loaded by Listener.

My solution:

Follow the following configuration to prevent spring from scanning the @ Service annotation class when the application is started. The servlet configuration file is written as follows:

<Context: component-scan base-package = "org. test">
<Context: exclude-filter type = "annotation" expression = "org. springframework. stereotype. Service"/>
</Context: component-scan>


Added the following content in the listener context:

<Context: component-scan base-package = "org. test"> </context: component-scan>

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.