项目结构如图,基本的spring的配置就不在赘述

1.首先编写自定义的切面类

package org.wu.test;

import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
@Component
@Aspect
public class DIv {
@Pointcut("execution(* org.wu.test.WyzController.say(..))")
public void aspect(){

}

@Before("aspect()")
public void dobefore(){
System.out.println("开始");
}
@AfterReturning("aspect()")
public void doAfter(){
System.out.println("结束");
}

}

@Component:然组件扫描注入到spring容器管理
@Aspect 指定切面类

@Pointcut() 指定切入点

@Before("aspect()")前置通知

package org.wu.test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitterReturnValueHandler;

@Controller
public class WyzController {
@Autowired
private Wyz wyz;

@RequestMapping("/say")
public String say() throws Exception {
wyz.say();
return "";
}

}要操作的类,就是把切面的作用指定带这个类的say方法上

这就完成了一个很简单的aop应用实例

最新文章

  1. 跨域之URL
  2. SQL Server 2008 中收缩数据库(DUMP,TRANSACTION,TRAN,无效,语法错误)
  3. [.net 面向对象编程基础] (11) 面向对象三大特性——封装
  4. picasso总结
  5. 在单机Hadoop上面增加Slave
  6. HW4.6
  7. NSMakeRange基础函数应用
  8. plupload插件的错误SCRIPT601
  9. [周译见] C# 7 中的模范和实践
  10. 模拟controfile丢失与重建
  11. JavaEE中的MVC(三)定制Struts——命令模式
  12. Lucene入门简介
  13. javap反汇编命令
  14. 【转载】ubuntu下/usr/bin和/usr/local/bin的区别
  15. One point compactification
  16. gentoo usb serial ch340 16进制读写
  17. [C#]使用RabbitMQ模拟抽奖系统的例子
  18. jenkins + sonar 安装配置
  19. XTU1236 Fraction
  20. 一致性 hash 算法( consistent hashing )(转)

热门文章

  1. 总结下Redux
  2. FineReport中如何对cpt模板加密
  3. AngularJS 和 Bootstrap
  4. 详解连接SQL Server数据库的方法,并使用Statement接口实现对数据库的增删改操作
  5. 在Windows上安装Elasticsearch v5.4.2
  6. 企业QQ客服的添加
  7. Ambari安装之部署单节点集群
  8. mysql浅龟定
  9. (转)volatile关键字
  10. 学生成绩管理系统——C语言实现