java--Aop--记录日志
package com.pt.modules.log; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.pt.modules.cfca.util.OutLogTextUtil;
import com.pt.modules.contract.rmtcontractlog.dto.RmtContractLogDTO;
import com.pt.modules.contract.rmtcontractlog.service.RmtContractLogService;
import com.pt.modules.contract.utils.Customannotations.OperationDescription; @Aspect
@Scope("prototype")
public class LoanLogAspect { private Logger logger = LoggerFactory.getLogger(LoanLogAspect.class); // 缓存有@OperationDescription方法参数名称
private static Map<String, String[]> parameterNameCaches = new ConcurrentHashMap<String, String[]>();
/**
* 接口请求记录实例
*/
@Autowired
@Qualifier("com.pt.modules.contract.rmtcontractlog.service.RmtContractLogService")
private RmtContractLogService rmtContractLogService; @Around("execution(* com.pt.modules.*.rest.*Rest*.*(..)) && @annotation(annotation)")
public Object advice(ProceedingJoinPoint joinPoint, OperationDescription annotation) throws Throwable{
String descption = annotation.description();
String entityType = annotation.entityType();
String reqContent = JSON.toJSONString(joinPoint.getArgs());
logger.info("\n\n"+OutLogTextUtil.outLogText("--接口名称----"+entityType+"-----操作动作:----"+descption+"---拦截器-接收到请求报文------------"+ reqContent));
Object result = joinPoint.proceed();
JSONObject response = JSON.parseObject(JSON.toJSONString(result));
response = response.getJSONObject("body");
String retcode = response.getString("retCode");
String errorDesc = response.getString("errorDesc");
RmtContractLogDTO dto = new RmtContractLogDTO();
dto.setErrMessage(errorDesc);
if(retcode!=""&&retcode!=null&&"302".equals(retcode)){
dto.setState("0");//失败状态
}else{
dto.setState("1");//成功状态
dto.setErrMessage(null);
}
this.saveRmtContractLog(dto, reqContent, "外部系统调用", entityType, descption,response.toString());
logger.info("\n\n"+OutLogTextUtil.outLogText("--接口名称----"+entityType+"-----操作动作:----"+descption+"---拦截器-返回接口报文------------"+ response.toString()));
return result;
} public void saveRmtContractLog(RmtContractLogDTO dto,String requestJson,String Systemsource ,
String interfaceName,String reqmapping,String responseJson) throws Exception{
dto.setSystemsource(Systemsource);
dto.setInterfaceName(interfaceName);
dto.setRequestJson(requestJson);
dto.setReqmapping(reqmapping);
dto.setResponseJson(responseJson);
rmtContractLogService.insertRmtContractLog(dto);
} }
package com.pt.modules.contract.utils.Customannotations; import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; @Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
public @interface OperationDescription {
/**
* 方法描述
* @return
*/
public String description() default "no description"; /**
* 操作
* @return
*/
public String entityType() default "";
}
<aop:aspectj-autoproxy proxy-target-class="true" />
<bean id="loanLogAspect" class="com.pt.modules.log.LoanLogAspect" />
java--Aop--记录日志的更多相关文章
- Java AOP (1) compile time weaving 【Java 切面编程 (1) 编译期织入】
According to wikipedia aspect-oriented programming (AOP) is a programming paradigm that aims to inc ...
- Java AOP (2) runtime weaving 【Java 切面编程 (2) 运行时织入】
接上一篇 Java AOP (1) compile time weaving [Java 切面编程 (1) 编译期织入] Dynamic proxy 动态代理 Befor talking abou ...
- java AOP使用注解@annotation方式实践
java AOP使用配置项来进行注入实践 AOP实际开发工作比较常用,在此使用注解方式加深对面向切面编程的理解 废话不多少,先看下面的实例代码 场景: 1.未满一岁的小孩,在执行方法之前打印:“ ...
- java AOP使用配置项来进行注入实践
java AOP使用注解@annotation方式实践 场景: 在目标方法前面和后面执行通知方法 目标类 @Component public class Play { public void watc ...
- Java AOP的底层实现原理
Java AOP的底层实现原理 一.什么是AOP 1.AOP:Aspect Oriented Programming(面向切面编程),OOP是面向对象编程,AOP是在OOP基础之上的一种更高级的设计思 ...
- Java AOP nested exception is java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice || Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0' 两个异常解决办法
贴出applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans ...
- Java AOP - Aspectj
1. 序 Aspect Oriented Programming (AOP)是近来一个比较热门的话题. AspectJ是AOP的Java语言的实现,获得了Java程序员的广泛关注. 关于AspectJ ...
- 在JAVA中记录日志的十个小建议
JAVA日志管理既是一门科学,又是一门艺术.科学的部分是指了解写日志的工具以及其API,而选择日志的格式,消息的格式,日志记录的内容,哪种消息对应于哪一种日志级别,则完全是基于经验.从过去的实践证明, ...
- java aop 日志打印 正则设置
package tz.lion.Utils.aop; import com.alibaba.fastjson.JSON;import org.springframework.web.multipart ...
- Java AOP总结
AOP AOP(Aspect Oriented Programming),即面向切面编程,可以说是OOP(Object Oriented Programming,面向对象编程)的补充和完善.OOP引入 ...
随机推荐
- UNION An Unreferenced Metric for Evaluating Open-ended Story Generation精读
UNION An Unreferenced Metric for Evaluating Open-ended Story Generation精读 UNION: 一种评估开放故事生成无参考文本依赖me ...
- Java实现RS485串口通信
前言 前段时间赶项目的过程中,遇到一个调用RS485串口通信的需求,赶完项目因为楼主处理私事,没来得及完成文章的更新,现在终于可以整理一下当时的demo,记录下来. 首先说一下大概需求:这个项目是机器 ...
- python使用msgpack(umsgpack)
前言 如果有业务需要将一个数据塞进队列由另一端接收,我们就需要考虑到数据的大小,因为这跟队列的效率和稳定性正相关,如果你希望能对这部分数据进行一定的压缩,并且提高解压缩的效率时,希望你能想到 msgp ...
- SIGGRAPH Asia 2020 电脑动画节(CAF)获奖短片出炉!
电脑动画节(CAF) 是SIGGRAPH Asia盛会最受瞩目的环节之一.2020年12月15日,SIGGRAPH Asia 2020虚拟线上会议正式宣布了电脑动画节的三部获奖短片:最佳作品奖< ...
- 2020周阳SpringCloud完整版笔记--一
微服务架构入门 微服务 的概念最早产生于Martin Fowler在2014年的一篇论文中. 微服务架构是一种架构模式,他提倡将单一应用程序划分成一组小的服务,服务与服务之间互相协调.相互配合,为用户 ...
- leetcode-222完全二叉树的节点个数
题目 给出一个完全二叉树,求出该树的节点个数. 说明: 完全二叉树的定义如下:在完全二叉树中,除了最底层节点可能没填满外,其余每层节点数都达到最大值,并且最下面一层的节点都集中在该层最左边的若干位置. ...
- requests+BeautifulSoup | 爬取电影天堂全站电影资源
import requests import urllib.request as ur from bs4 import BeautifulSoup import csv import threadin ...
- (二)数据源处理4-excel部分封装及数据转换
excel02.py # -*- coding: utf-8 -*-#@File :excel_oper_02.py#@Auth : wwd#@Time : 2020/12/7 8:16 下午impo ...
- 原生javascript制作省市区三级联动详细教程
多级联动下拉菜单是前端常见的效果,省市区三级联动又属于其中最典型的案例.多级联动一般都是与数据相关联的,根据数据来生成和修改联动的下拉菜单.完成一个多级联动效果,有助于增强对数据处理的能力. 本实例以 ...
- kubernets集群的安全防护(下)
一 集群角色以及集群角色绑定 1.1 前面我们提到过角色以及角色绑定,那么现在为什么会出现集群级别的角色以及角色绑定,作用有如下所示 我们如果需要在所有的命名的空间创建某个角色或者角色绑定的时候 ...