Annotation方式实现AOP
1、添加其他jar包

2、配置applicationContext.xml文件
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
<?xml version="1.0" encoding="UTF-8"?> xsi:schemaLocation="http://www.springframework.org/schema/beans <context:annotation-config /> <context:component-scan base-package="com.fz.annotation" /> <aop:aspectj-autoproxy /> </beans> |
3、编写切面类LogInterceptor.java
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package com.fz.annotation.aop;import org.aspectj.lang.ProceedingJoinPoint;import org.aspectj.lang.annotation.AfterReturning;import org.aspectj.lang.annotation.AfterThrowing;import org.aspectj.lang.annotation.Around;import org.aspectj.lang.annotation.Aspect;import org.aspectj.lang.annotation.Before;import org.aspectj.lang.annotation.Pointcut;import org.springframework.stereotype.Component;@Aspect@Componentpublic class LogInterceptor { @Pointcut("execution(public void com.fz.annotation.service.impl.UserServiceImpl.userAdd(com.fz.xml.entity.User))") public void myMethod(){}; @Before("myMethod()") public void before(){ System.out.println("方法之前执行...."); } @AfterReturning("myMethod()") public void afterRutting(){ System.out.println("方法正常执行之后...."); } @AfterThrowing("myMethod()") public void afterThrowing(){ System.out.println("方法抛出异常之后...."); } @Around("myMethod()") public void around(ProceedingJoinPoint pjp) throws Throwable{ System.out.println("方法执之前around......");//这里会优先于@Before先执行 pjp.proceed();//向下继续方法的执行:(包括执行其他切面的拦截,如果当中抛出异常,则不会向下继续执行) System.out.println("方法执之后around......");//这里会在@AfterReturning执行之后执行 }} |
Annotation方式实现AOP的更多相关文章
- Annotation方式配置AOP
package com.xk.spring.kp04_aop.aop.s02_annotation; public interface IStudentService { public void sa ...
- Spring入门6事务管理2 基于Annotation方式的声明式事务管理机制
Spring入门6事务管理2 基于Annotation方式的声明式事务管理机制 201311.27 代码下载 链接: http://pan.baidu.com/s/1kYc6c 密码: 233t 前言 ...
- 菜鸟学习Spring——60s使用annotation实现简单AOP
一.概述. AOP大家都知道切面编程,在Spring中annotation可以实现简单的AOP列子.下面还未大家介绍几个概念: Aspect 对横切性关注点的模块化. Advice 对横切性关注点的具 ...
- 使用Spring框架入门四:基于注解的方式的AOP的使用
一.简述 前面讲了基于XML配置的方式实现AOP,本文简单讲讲基于注解的方式实现. 基于注解的方式实现前,要先在xml配置中通过配置aop:aspectj-autoproxy来启用注解方式注入. &l ...
- 基于AspectJ的注解方式进行AOP开发
-------------------siwuxie095 基于 AspectJ 的注解方式进行 AOP 开发 ...
- Spring整合Hibernate:2、使用Annotation方式进行声明式的事务管理
1.加入DataSourceTransactionManager的命名空间 修改applicationContext.xml文件,增加如下内容: 1 2 3 4 5 6 7 8 9 10 11 12 ...
- 特性attribute,声明和使用attribute,应用attribute,AOP面向切面,多种方式实现AOP
1 特性attribute,和注释有什么区别2 声明和使用attribute3 应用attribute4 AOP面向切面5 多种方式实现AOP ---------------------------- ...
- 一起学Spring之注解和Schema方式实现AOP
概述 在上一篇,我们了解了通过实现接口和XML配置的方式来实现AOP,在实现注解方式AOP之前,先了解一下AspectJ.AspectJ是一个面向切面的框架,它扩展了Java语言,定义了AOP语法,能 ...
- Spring系列之aAOP AOP是什么?+xml方式实现aop+注解方式实现aop
Spring系列之aop aop是什么?+xml方式实现aop+注解方式实现aop 什么是AOP? AOP为Aspect Oriented Programming 的缩写,意识为面向切面的编程,是通过 ...
随机推荐
- 金融即服务(FaaS),将开启场景化金融新格局
转自: https://www.iyiou.com/p/28494/fs/1 [ 亿欧导读 ] 金融即服务揭示了场景金融的实现路径,通过双向连接做一个开放的系统,按需给客户提供金融服务. 本文系作者在 ...
- Ubuntu中安装Flask模块
pip3 list——python3下安装的***** #如果列表没有flask pip3 install flask即可
- 读写文件时0A转化为0D 0A
转自:http://www.cnblogs.com/congdiaodiao/p/4529785.html 用C++写东西,需要往文件里写数据,很简单的代码,大概是这个样子: #include < ...
- Linux学习笔记之Xshell配色方案定制
点击 Xshell 面板顶部的如下按钮. 点击 Browse 按钮,弹出如下面板,选择 ANSI Colors on Black,然后点击右侧save as 按钮,命名为 zkl. 这里其实就是复 ...
- python windows打包
接触过的工具有pyinstaller,或者py2exe.感觉pyinstaller更简单易用. 真正将依赖的dll打包称一个安装包还需要借助windows打包工具 Inno Setup 或 NSIS ...
- 20145321 《Java程序设计》第8周学习总结
20145321 <Java程序设计>第8周学习总结 教材学习内容总结 第十五章 时间与日期 15.1 日志 1.使用日志的起点是Logger类,要取得Logger类,必须使用Logger ...
- 打开Mac OSX原生的NTFS功能
插上磁盘 从finder或者使用以下命令查看到磁盘的Volume Name: diskutil list /dev/disk0 #: TYPE NAME SIZE IDENTIFIER 0: GUID ...
- Spring容器基础ClassPathXmlApplicationContext(一起看源码)
ApplicationContext相比较于BeanFactory,扩展了很多功能.也就是说前者包含了后者的所有功能.使用前者加载XML的方式:ApplicationContext app=new C ...
- 【pytorch】pytorch基础学习
目录 1. 前言 # 2. Deep Learning with PyTorch: A 60 Minute Blitz 2.1 base operations 2.2 train a classifi ...
- detectron——test 错误集锦
一.测试错误,运行如下代码 python2 tools/test_net.py --cfg experiments/e2e_faster_rcnn_resnet--FPN_pascal2007.yam ...