Common reasons why spring declarative things don't work

Source: Internet
Author: User
Tags aop rollback
Common reasons why spring declarative things don't work

<!--transaction configuration: Transaction manager-->

<bean id= "TransactionManager"
class= "Org.springframework.orm.hibernate4.HibernateTransactionManager" >
<property name= "Sessionfactory" ref= "Sessionfactory"/>
<property name= "DataSource" ref= "DataSource"/>
</bean>

<aop:aspectj-autoproxy proxy-target-class= "true" expose-proxy= "true"/>

<aop:config>
<aop:advisor pointcut= "Execution (* Com.framework.common. *service*.* (..)) "
advice-ref= "Txadvice"/>
</aop:config>
<tx:advice id= "Txadvice" transaction-manager= "TransactionManager" >
<tx:attributes>
<tx:method name= "save*" propagation= "REQUIRED"
Rollback-for= "Exception"/>
<tx:method name= "update*" propagation= "REQUIRED"
Rollback-for= "Exception"/>
<tx:method name= "delete*" propagation= "REQUIRED"
Rollback-for= "Exception"/>
<tx:method name= "get*" read-only= "true"/>
<tx:method name= "query*" read-only= "true"/>
<tx:method name= "Pagequery" read-only= "true"/>
<tx:method name= "*" propagation= "REQUIRED" rollback-for= "Exception"/>
</tx:attributes>
</tx:advice>
Ps:
1, applicationcontext.xml note Enable <aop:aspectj-autoproxy proxy-target-class= "true" expose-proxy= "true"/>
2, APPLICATIONCONTEXT.XMLL attention expression= "Execution" (* Com.xx.xxx.service ... *(..)) "The right to write
3, if you are using the Spring MVC approach, pay attention to the Applicationcontext-springmvc.xml file <context:component-scan base-package= "com.xx.xxx"/ > May cause your service (at this point not to produce things related to the agent class) ahead of loading, resulting in the configuration of things does not work.

Workaround:

Applicationcontext-springmvc.xml adds the following configuration, declaring that spring MVC is initialized with only scanning controller.

<context:component-scan base-package= "Com.framework" use-default-filters= "false" >
<context:include-filter expression= "Org.springframework.stereotype.Controller" type= "annotation"/>
</context:component-scan>

APPLICATIONCONTEXT.XMLL adds the following configuration, declaring spring initialization without scanning controller.

<context:component-scan base-package= "Com.framework" >
<context:exclude-filter expression= "Org.springframework.stereotype.Controller" type= "annotation"/>

</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.