spring AOP使用注解无法执行的问题
2017-10-25 12:33
465 查看
spring AOP使用注解无法执行的问题
今天项目中想用spring的aop切面功能,代码如下:定义一个简单的切面类
@Aspect @Component("loginInterceptor") public class LoginInterceptor { @Before("execution(* com.bibo.service.controller.TestAop.*(..))") public void before(){ System.err.println("method start..."); } }
spring的配置文件
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> <aop:aspectj-autoproxy/> <context:annotation-config /> <context:component-scan base-package="**.controller" /> <!-- 激活处理@ Controller类(注释支持驱动的格式和注释驱动的验证) --> <mvc:annotation-driven />
基本项目代码就是这样,但是测试的时候,切面就是不执行….
首先检查切面类和controller是否都被spring管理,经过检查,没问题…
各种检查切面语法,也没问题。
最后看到CSDN一个大神说:项目使用了spring mvc,把
<aop:aspectj-autoproxy/>配置放到spring mvc的配置中,试了一下,果然可以了。
记录下来,以后千万记住!!
相关文章推荐
- 使用dubbo注解@Service注册服务后使用aop或者申明式事物导致无法注册的问题解决办法
- spring aop 和Transaction一起使用执行顺序问题
- 解决ssh远程执行命令无法使用awk的问题
- spring aop 功能初次使用(注解方式)
- Spring 下事务管理-使用AOP @Transactional注解管理
- (9) 使用Spring的注解方式实现AOP入门 以及 细节
- 几个问题(十)-------spring的IOC、AOP的使用场景
- ITCAST视频-Spring学习笔记(使用Spring的注解方式实现AOP的细节)
- 在Eclipse RCP中使用Spring AOP/ProxyFactory的问题
- quartz 框架定时任务,使用spring @Scheduled注解执行定时任务
- 使用Spring的注解方式实现AOP
- 使用复制存储过程执行解决“事务复制中的表大量更新导致无法及时同步”的问题
- spring.net 1.1.0 P3版本 中spring.core.dll 1.1.0.2版本对于AOP使用ADVICE中涉及使用ref/out参数的小问题
- spring aop的使用(注解方式以及基于xml配置方式)
- 使用spring @Scheduled注解执行定时任务、
- 使用Jmeter对Mysql进行压力测试无法执行多条sql语句问题
- 使用Spring的注解方式实现AOP
- 在SSH框架下使用基于配置的Spring3的调度任务每次执行2次的问题
- 使用 spring aop 在DispatchAction中遇到的问题
- spring aop的使用(注解方式以及基于xml配置方式)