经常遇到aop-aspectJ的通知不被执行的问题

解决方法:http://blog.csdn.net/qwdafedv/article/details/53005210

首先,确保配置文件都已经是正确的。

1、首先,把所写的通知所在的类交于spring来管理

<context:component-scan base-package="me.sui.user.aop" />

注意,其头部文件:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd ">

2、然后,应该还有一条

<aop:aspectj-autoproxy/>

之所以没有和上面放在一起,等会再说。

3、切面通知类

package me.sui.user.aop;

import javax.servlet.http.HttpServletRequest;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component; /**
* 注册切面
* @author qubianzhong
*
*/
@Aspect
@Component
public class RegisterAspect { /**
* studentService
*/
@Autowired
@Qualifier("studentService")
private StudentService studentService;
/**
* 后置通知,用户注册成功后,将注册数据信息发送到神策数据进行分析
* @param joinPoint 接入点
* @param result 目标方法的返回结果
*/
@AfterReturning(value="execution(* me.sui.user.rest.StudentRestController.register(..))", returning = "result")
public void afterMethod(JoinPoint joinPoint,Object result){
if((boolean) result){ }
}
}

4、以上都准备妥当后,通知还不可以被执行,是因为下面这几个坑:

一、我所拦截的类,即被切的类,是个servlet;只有当切面类和被切面类都被spring来管理的时候,通知才可以使用。


二、基于第一条,如果你换成拦截器也是不行的。


三、如果你使用的是springMVC,你所拦截的切面类也是个controller,但是,还是不行,可能就是因为你把

<aop:aspectj-autoproxy/>

也放在了application.xml中了。可能是springmvc的bug吧。你把

<aop:aspectj-autoproxy/>

放到DispatcherServlet所对应的**-servlet.xml配置文件中,就可以了。

 

spring aop:aspectj-autoproxy 配置的更多相关文章

  1. Spring学习之旅(八)Spring 基于AspectJ注解配置的AOP编程工作原理初探

    由小编的上篇博文可以一窥基于AspectJ注解配置的AOP编程实现. 本文一下未贴出的相关代码示例请关注小编的上篇博文<Spring学习之旅(七)基于XML配置与基于AspectJ注解配置的AO ...

  2. 关于 Spring AOP (AspectJ) 该知晓的一切

    关联文章: 关于Spring IOC (DI-依赖注入)你需要知道的一切 关于 Spring AOP (AspectJ) 你该知晓的一切 本篇是年后第一篇博文,由于博主用了不少时间在构思这篇博文,加上 ...

  3. spring aop两种配置方式

    基于注解的Spring AOP开发 简单案例快速入门 定义目标类接口和实现类 /** * Created by zejian on 2017/2/19.*/ //接口类 public interfac ...

  4. 关于 Spring AOP (AspectJ) 你该知晓的一切

    版权声明:本文为CSDN博主「zejian_」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明.原文链接:https://blog.csdn.net/javazej ...

  5. Spring AOP + AspectJ annotation example

    In this tutorial, we show you how to integrate AspectJ annotation with Spring AOP framework. In simp ...

  6. Spring AOP + AspectJ Annotation Example---reference

    In this tutorial, we show you how to integrate AspectJ annotation with Spring AOP framework. In simp ...

  7. Spring学习(十八)----- Spring AOP+AspectJ注解实例

    我们将向你展示如何将AspectJ注解集成到Spring AOP框架.在这个Spring AOP+ AspectJ 示例中,让您轻松实现拦截方法. 常见AspectJ的注解: @Before – 方法 ...

  8. 关于 Spring AOP (AspectJ) 你该知晓的一切 (转)

    出处:关于 Spring AOP (AspectJ) 你该知晓的一切

  9. spring aop两种配置方式(1)

    第一种:注解配置AOP注解配置AOP(使用 AspectJ 类库实现的),大致分为三步: 1. 使用注解@Aspect来定义一个切面,在切面中定义切入点(@Pointcut),通知类型(@Before ...

  10. java框架篇---spring aop两种配置方式

    第一种:注解配置AOP 注解配置AOP(使用 AspectJ 类库实现的),大致分为三步: 1. 使用注解@Aspect来定义一个切面,在切面中定义切入点(@Pointcut),通知类型(@Befor ...

随机推荐

  1. spark学习笔记3

    Spark 支持在集群范围内将数据集缓存至每一个节点的内存中,可避免数据传输,当数据需要重复访问时这个特征非常有用,例如查询体积小的“热”数据集,或是运行如 PageRank 的迭代算法.调用 cac ...

  2. python——二分查找算法

    从有序列表的候选区data[0:n]开始,通过对待查找的值与候选区中间值的比较,可以使候选区减少一半   二分查找: 在一段数字内,找到中间值,判断要找的值和中间值大小的比较. 如果中间值大一些,则在 ...

  3. 利用Python进行自然语言处理(笔记)第一章

    一.标识符 一个我们想要放在一组对待的字符序列--如:”hairy“.”his“或者”:“: 二.词类型 一个词在一个文本中独一无二的出现形式或拼写,也就是说这个词在词汇表中是唯一的.如果我们计数的项 ...

  4. java上传文件代码

    import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;impo ...

  5. php 的函数

    一.函数定义及变量作用域 1. 函数的声明和调用 函数的目的是复用. [$variable=] function [name]([$param]){} 2. 变量的作用域 (1) 全局变量 函数内部想 ...

  6. Mysql事务原理介绍

    事务 一个事务会涉及到大量的cpu计算和IO操作,这些操作被打包成一个执行单元,要么同时都完成,要么同时都不完成. 事务是一组原子性的sql命令或者说是一个独立的工作单元,如果数据库引擎能够成功的对数 ...

  7. 005-docker-镜像使用、拉取、运行、创建、打tag

    当运行容器时,使用的镜像如果在本地中不存在,docker 就会自动从 docker 镜像仓库中下载,默认是从 Docker Hub 公共镜像源下载. 1.列出所有本地镜像 docker images ...

  8. git branch 命令查看分支、删除远程分支、本地分支

    git branch 命令操作 1.查看本地分支 : git branch 前面带有*号的是当前分支 2 .删除本地分支: git branch -d [branchname] 提示删除了一个名为li ...

  9. O(N)的时间寻找最大的K个数

    (转:http://www.cnblogs.com/luxiaoxun/archive/2012/08/06/2624799.html) 寻找N个数中最大的K个数,本质上就是寻找最大的K个数中最小的那 ...

  10. vertical-align:middle实现图片与文字垂直居中对齐

    css代码: header .logo{ display:inline-block; margin-left: 10px; width: 15%; line-height: 9.1rem; backg ...