spring-aop增强问题

tech2025-09-14  6

spring事务增强功能未实现原因

问题描述

单独使用测试类加载spring-mybatis整合配置文件可以实现aop增强功能,同时加载spring-mybatis和springMVC配置文件整合aop增强功能失效。

测试方法

单独使用一个ssm整合配置文件可以实现aop增强功能。

原因分析

说明web容器加载完spring-mybatis配置文件后,在springMVC配置文件加载ioc容器时覆盖了service类在ioc容器中的bean实例

测试方法

使用两个配置文件,同时spring-mybatis添加

<context:component-scan base-package="com.nerber" > <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan>

springMVC配置文件添加

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

以上配置可以实现aop增强

当springMVC中不使用

user-default-filters="false"

无法实现aop增强。

配置文件中都使用exclude-filter时,也可以实现aop增强。

原因分析

include-filter需要和use-default-filters结合使用才能生效

最新回复(0)