应用AOP把spring mvc controller办法的参数输出到日志
Advisor
pakcage com.iteye.dwangel.util.spring;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Method;
/**
* AOP advicer to get log
* Created by Simon Xianyu on 2015/11/18 0018.
*/
@Aspect
public class MvcMethodLogAdvice {
private static Logger log = LoggerFactory.getLogger("com.iteye.dwangel.MVC");
@Around("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
public Object aroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
Object args[] = joinPoint.getArgs();
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
// join arguments.
log.debug("{}.{} : {} ",method.getDeclaringClass().getName(), method.getName(), StringUtils.join(args," ; "));
return joinPoint.proceed();
}
}
pak