Aspect注解实现简单的切面
来源:互联网 发布:la mer 眼霜 知乎 编辑:程序博客网 时间:2024/06/02 16:38
1.使用Aspect,注意首先下载需要的jar包,导入工程。
2.需要一个类作为切面类。
3.切面类代码:
@Aspect
public class Aop {
@Pointcut("execution(* *.eat(..))") (两个星号代表匹配所有eat方法,@Pointcut("execution(* bean.North.eat(..))")则对应的一个方法)
public void eat(){};
//前置方法
@Before("eat()")
public void before(){
System.out.println("方法之前...");
}
//后置方法
@After("eat()")
public void behind(){
System.out.println("方法之后...");
}
}
4.xml 中添加: <aop:aspectj-autoproxy/> <!-- 要添加本行 -->
5.错误提示:
ApplicationContext ac = new FileSystemXmlApplicationContext("src/applicationContext.xml");//利用文件系统查询applicationContext.xml配置文件
Person p = (North) ac.getBean("north");
p.eat();
********** com.sun.proxy.$Proxy8 cannot be cast to bean.North (控制台错误提示)!
改为:
ApplicationContext ac = new FileSystemXmlApplicationContext("src/applicationContext.xml");//利用文件系统查询applicationContext.xml配置文件
Person p = (Person) ac.getBean("north");
p.eat();
- Aspect注解实现简单的切面
- 基于spring注解切面的简单实现
- 自定义注解 Aspect 实现aop 日志记录切面编程
- spring 基于Aspect和注解的切面编程(aop)
- 基于注解@Aspect的AOP实现
- Spring 基于 Aspect 注解的增强实现
- Spring注解实现AOP(面向切面编程Aspect Oriented Programming,AOP)
- 什么是基于注解的切面实现
- spring切面切点@Aspect的使用
- springmvc Aspect 实现自定义注解的日志记录
- spring Aspect 实现自定义注解的日志记录,有时候注解类不起作用的原因分析
- spring Aspect 切面日志
- SpringBoot(七)Aspect切面
- spring切面(aspect)配置
- aspect 面向切面编程
- @Aspect注解形式实现AOP实例
- AOP切面之实现计算器加减乘除--基于注解的方式
- SpringAOP:简单的Aspect案例
- 密度聚类算法(二)
- 持久化对象的状态、Hibernate配置文件、映射对象标识符 、 映射组成关系 、 Hibernate把持久话类的属性分为两种
- XiaomiRouter自学之路(05-U-boot配置编译烧录)
- Lucene初探之数据格式详情(四)
- codewars c++8分题(1)
- Aspect注解实现简单的切面
- 地图服务
- C++ Template 基础篇(二):类模板
- 在Linux(deepin)系统中搭建Android开发环境
- leetcode515 Find Largest Value In Each Tree Row Java
- Essential C++ 之面向过程
- 阿里云搭建tomcat服务
- [51NOD] 1001 数组中和等于K的数对 [二分]
- java中的线程安全