本文章主要是基于方法级别的aop实现,即在方法上添加注解,实现aop的日志落表
1、基于xml实现
目录结构
日志注解类:
package com.aopmethod.transaction;
import java.lang.annotation.*;
@Target({ElementType.METHOD,ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface LoggerAspect {
/** 要执行的操作类型比如:比如接收接口,发送接口 **/
String operationType() default "";
/** 要执行的具体操作比如:方法名称 **/
String operationName() default "";
}
日志实现类:
package com.aopmethod.transaction;
import com.alibaba.fastjson.JSON;
import com.ouyeel.platform.components.rzcore.foundation.dao.sjd.InterfaceInstructionsMapper;
import com.ouyeel.platform.components.rzcore.foundation.model.sjd.InterfaceInstructionsWithBLOBs;
import org.aspectj.lang.JoinPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Resource;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;
import java.util.UUID;
public class ArchivesLogAspect {
private final static Logger logger = LoggerFactory.getLogger(ArchivesLogAspect.class);
@Resource
private InterfaceInstructionsMapper interfaceInstructionsMapper;
/**
* 注解到Method ,进行日志管理
* 返回通知(在方法正常结束执行的代码)
* @param
* joinPoint --获取方法基础信息
* result --方法返回值
*/
public void afterReturnMethod(JoinPoint joinPoint, Object result){
String targetName = joinPoint.getTarget().getClass().getName(); //类名
String methodName = joinPoint.getSignature().getName(); //方法名
Object[] arguments = joinPoint.getArgs(); //参数
logger.info("类名:"+targetName+",方法名:"+methodName);
Class targetClass = null;
try {