Troubled sprint mvc transaction is finally resolved.

The recent introduction spring mvc framework to build a project and found that the transaction does not work, busy day, various programs, is not.

Later on google to see an article, suddenly, they are not matters configuration issues that place, but the scanning assembly annotation bean issue.

Original excerpt, such as washing:

Because the context is spring Sons container, it will conflict, ServletContextListener is generated by the parent container, the assembly is produced springMVC example @Service annotated child container when the sub scanning Controller container assembly, and this example should a parent container initialized to ensure enhanced handling affairs, so in this case would be to get as-Service (no strengthening treatment after the transaction, and therefore no transaction capabilities.


I applicationContext.xml original file as follows:

    <context:component-scan base-package="x.y">
        <context:include-filter type="aspectj" expression="x.y..*Dao+"/>
        <context:include-filter type="aspectj" expression="x.y..*SQL+"/>
        <context:include-filter type="aspectj" expression="x.y..*Service+"/>
    </context:component-scan>


web-servlet.xml file as follows:

    <context:component-scan base-package="x.y">
        <context:include-filter type="aspectj" expression="x.y..*Controller+"/>
    </context:component-scan>   


applicationContext.xml modified file as follows:

    <context:component-scan base-package="x.y">
        <context:include-filter type="aspectj" expression="x.y..*Dao+"/>
        <context:include-filter type="aspectj" expression="x.y..*SQL+"/>
        <context:include-filter type="aspectj" expression="x.y..*Service+"/>
        <context:exclude-filter type="aspectj" expression="x.y..*Controller+"/>
    </context:component-scan>

web-servlet.xml file as follows:

    <context:component-scan base-package="x.y">
        <context:include-filter type="aspectj" expression="x.y..*Controller+"/>
        <context:exclude-filter type="aspectj" expression="x.y...*Service+"/>

    </context:component-scan>   


Although the cause know, the problem is solved, but one thing still do not understand.

为何不写 <context:exclude-filter type="aspectj" expression="x.y...*Service+"/>

Loading service will come in? Could include-filter is to eat cooked rice? ?


Reproduced in: https: //my.oschina.net/cjkall/blog/195905

Guess you like

Origin blog.csdn.net/weixin_33853794/article/details/91756527