spring AOP使用注解无法执行的问题

来源:互联网 发布:网络直播相关法律出台 编辑:程序博客网 时间:2024/06/04 19:31

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的配置中,试了一下,果然可以了。
记录下来,以后千万记住!!