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引入 ...
随机推荐
- 痞子衡嵌入式:MCUXpresso IDE下添加新路径下源文件进工程编译的方法
大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是MCUXpresso IDE下添加新路径下源文件进工程编译的方法. 接着上篇文章 <MCUXpresso IDE下SDK工程导入与 ...
- Spring用了哪些设计模式?
设计模式是一套被反复使用的.多数人知晓的.经过分类编目的.代码设计经验的总结.总共有 23 种设计模式 使用设计模式是为了重用代码.让代码更容易被他人理解.保证代码可靠性. Spring用了哪些设计模 ...
- (数据科学学习手札102)Python+Dash快速web应用开发——基础概念篇
本文示例代码与数据已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 这是我的新系列教程Python+Dash快 ...
- TypeLoadException: 未能从程序集“ECS.GUI.Define, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”中加载类型“ECS.GUI.Define.ArmgAimPos”,因为它在 4 偏移位置处包含一个对象字段,该字段已由一个非对象字段不正确地对齐或重叠
TypeLoadException: 未能从程序集"ECS.GUI.Define, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null ...
- MongoDB备份(mongoexport)与恢复(mongoimport)
1.备份恢复工具介绍: mongoexport/mongoimport mongodump/mongorestore(本文未涉及) 2.备份工具区别在哪里? 2.1 mongoexport/mongo ...
- Lambda获取类属性的名字
using System; using System.ComponentModel; using System.Linq.Expressions; using System.Reflection; p ...
- zabbix 4.X 版本 web字体显示方块
先看看问题长啥样...... Zabbix 字体乱码(显示呈现方块) 第一种解决方法: # 1) 进入代码存放目录的字体目录: cd /data/www/zabbix/assets/fonts # 2 ...
- 【Oracle】更改oracle中的用户名称
修改oracle中的用户名,要需要修改oracle基表中的相关内容, 1.查看user#, select user#,name from user$ s where s.name='用户修改前的'; ...
- LeetCode1022. 从根到叶的二进制数之和
题目 class Solution { public: int ans = 0; int sumRootToLeaf(TreeNode* root) { dfs(root,0); return ans ...
- 边缘计算k8s集群SuperEdge初体验
前言 手上一直都有一堆的学生主机,各种各样渠道途径拿来的机器. 一直管理里面都比较蛋疼,甚至也不太记得住它们在哪是什么IP,管理起来很是头疼. 有阵子空闲的时候想折腾了一下边缘计算集群方案. 希望能把 ...