Bootstrap

利用springaop实现日志输出

需求:利用aop思想实现日志输出,加了注解的方法忽略打印日志,下面请看具体实现。

1.编写切面

注意:注意查看execution访问的方法修饰符,默认是方法public方法,如果是private需要手动修改。

package com.bandweaver.tunnel.common.platform.log;

import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Date;
import java.util.Set;
import java.util.UUID;

import javax.management.RuntimeErrorException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.shiro.SecurityUtils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.xml.sax.SAXException;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bandweaver.tunnel.common.biz.dto.UserDTO;
import com.bandweaver.tunnel.common.biz.itf.OperationLogService;
import com.bandweaver.tunnel.common.biz.itf.SecurityLogService;
import com.bandweaver.tunnel.common.biz.itf.UserService;
import com.bandweaver.tunnel.common.biz.pojo.OperationLog;
import com.bandweaver.tunnel.common.biz.pojo.SecurityLog;
import com.bandweaver.tunnel.common.biz.pojo.User;
import com.bandweaver.tunnel.common.platform.constant.Constants;
import com.bandweaver.tunnel.common.platform.constant.StatusCodeEnum;
import com.bandweaver.tunnel.common.platform.util.ContextUtil;

/**
 * ClassName: LogAspect
 * 
 * @Description: 日志切面
 * @author shaosen
 * @date 2018年5月16日
 */
@Aspect
@Component
public class LogAspect {

	
	private static final String OPTLOGID = "optLogId";
	@Autowired
	private OperationLogService operationLogService;
	@Autowired
	private SecurityLogService securityLogService;
	@Au
;