【spring aop切面】基础使用教程
package tpf.aspect; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component; import java.util.Arrays;
import java.util.HashMap;
import java.util.Map; /**
* Created by zipon on 2017/9/20.
*/
@Aspect
@Component
public class AspectTest {
private final static Log logger = LogFactory.getLog(AspectTest.class); private String joinPointInfo(JoinPoint joinPoint) {
return simpleJoinPointInfo(joinPoint) + " args:" + Arrays.toString(joinPoint.getArgs());
} private String simpleJoinPointInfo(JoinPoint joinPoint) {
return joinPoint.getTarget().getClass() + "#" + joinPoint.getSignature().getName();
} //定义切点
@Pointcut("execution(* tpf.controller.loginController.* (..))")
public void cutPublicMethod() {
} @Before("cutPublicMethod()")
public void logBefore(JoinPoint pjp) throws Throwable {
} @AfterReturning("cutPublicMethod()")
public void logAfter(JoinPoint pjp) throws Throwable {
} @Around("cutPublicMethod()")
public Object consumingAround(ProceedingJoinPoint joinPoint) throws Throwable {
System.out.println("**************登陆开始**************");
String joinPointInfo = joinPointInfo(joinPoint);
String simpleJoinPointInfo = simpleJoinPointInfo(joinPoint);
long startTime = System.currentTimeMillis();
logger.info("[API_START]" + joinPointInfo);
Object[] args = joinPoint.getArgs();
Object obj = joinPoint.proceed(args);
// logger.info("[API_END]" + simpleJoinPointInfo);
long endTime = System.currentTimeMillis();
long diffTime = endTime - startTime;
Map<String, String> map = new HashMap<String, String>();
map.put("method", simpleJoinPointInfo);
map.put("time", String.valueOf(diffTime));
map.put("start", String.valueOf(startTime));
map.put("end", String.valueOf(endTime)); //方法执行完,要用joinPoint.proceed();
joinPoint.proceed();
System.out.println("==================登陆结束后==================");
return obj;
} }
【spring aop切面】基础使用教程的更多相关文章
- spring AOP(切面) 表达式介绍
在 spring AOP(切面) 例子基础上对表达式进行介绍 1.添加接口删除方法 2.接口实现类 UserDaoServer 添加实现接口删除方法 3.测试类调用delUser方法 4. 输出结果截 ...
- Spring AOP切面的时候参数的传递
Spring AOP切面的时候参数的传递 Xml: <?xml version="1.0" encoding="UTF-8"?> <beans ...
- Spring AOP 切面编程记录日志和接口执行时间
最近客户现在提出系统访问非常慢,需要优化提升访问速度,在排查了nginx.tomcat内存和服务器负载之后,判断是数据库查询速度慢,进一步排查发现是因为部分视图和表查询特别慢导致了整个系统的响应时间特 ...
- 使用Spring AOP切面解决数据库读写分离
http://blog.jobbole.com/103496/ 为了减轻数据库的压力,一般会使用数据库主从(master/slave)的方式,但是这种方式会给应用程序带来一定的麻烦,比如说,应用程序如 ...
- 利用Spring AOP切面对用户访问进行监控
开发系统时往往需要考虑记录用户访问系统查询了那些数据.进行了什么操作,尤其是访问重要的数据和执行重要的操作的时候将数记录下来尤显的有意义.有了这些用户行为数据,事后可以以用户为条件对用户在系统的访问和 ...
- Spring AOP 切面编程的方法
spring aop的使用分为两种,一种是使用注解来实现,一种是使用配置文件来实现. 先来简单的介绍一下这两种方法的实现,接下来详细的介绍各处的知识点便于查阅.目录如下: 1.基于注解实现spring ...
- [Spring] Aspect Oriented Programming with Spring | AOP | 切面 | 切点
使用Spring面向切面编程 1.介绍 AOP是OOP的补充,提供了另一种关于程序结构的思路. OOP的模块化的关键单位是 类 . AOP的则是aspect切面. AOP 将程序的逻辑分成独立的块(叫 ...
- Spring AOP 切面实现操作日志
创建接口注解日志类 package com.fh.service.logAop; /** * Created by caozengling on 2018/7/21. */ import java.l ...
- spring AOP(切面)
AOP 基本概念cross cutting concern横切性关注点:独立服务,遍布在系统处理流程之中 Aspect对横切关注点模块化 advice对横切关注点具体实现 pointcut定义adv ...
- Spring aop切面插入事物回滚
<!-- tx标签配置 事物--> <tx:advice id="txadvice" transaction-manager="transactionM ...
随机推荐
- 使用Timer组件制作左右飘动的窗体
实现效果: 知识运用: Form类的Left和Top属性 实现代码: private void timer1_Tick(object sender, EventArgs e) { Rectangle ...
- 【转】JavaScript 节点操作 以及DOMDocument属性和方法
最近发现DOMDocument对象很重要,还有XMLHTTP也很重要 注意大小写一定不能弄错. 属性: 1Attributes 存储节点的属性列表(只读) 2childNodes 存储节点的子节点列表 ...
- js函数式编程(一)-纯函数
我将写的第一个主题是js的函数式编程,这一系列都是mostly adequate guide这本书的读书总结.原书在gitbook上,有中文版.由于原作者性格活泼,书中夹杂很多俚语,并且行文洒脱.中文 ...
- 【状压dp】cf906C. Party
需要稍加分析结论:还有一些小细节 Arseny likes to organize parties and invite people to it. However, not only friends ...
- Oracle 数据库常用SQL语句(2)查询语句
一.SQL基础查询 1.select语句 格式:select 字段 from 表名; 2.where 用于限制查询的结果. 3.查询条件 > < >= <= = != 4.与 ...
- vue-cli3.0相关的坑
vue-cli3.0相对比vue-cli2.0少了 vue-build.js vue-config.js vue-cli2.0 运行命令 npm run devvue-cli3.0 运行命令 npm ...
- python-matplotlib-lec0
直奔主题吧..以下是对matplotlib画图的简单讲解,代码已测试. win7 + pycharm + python 2.7 参考文档: http://old.sebug.net/paper/boo ...
- leetcode-14-basic-breadthFirstSearch
BFS: breadth first search 107. Binary Tree Level Order Traversal II 解题思路: 本来我是用map<int,int>存所有 ...
- ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph(有源上下界最大流 模板)
关于有源上下界最大流: https://blog.csdn.net/regina8023/article/details/45815023 #include<cstdio> #includ ...
- 更改activity切换方式
overridePendingTransition(enterAnim, exitAnim); Intent intent =new Intent(this,item2.class); startAc ...