제 코드 하 이 라 이 트 를 테스트 해 보 세 요.

1162 단어 자바apache.
package com.zzvcom.sysmag.aspect;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Arrays;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.ProceedingJoinPoint;

/**
 *     Aspect<br>
 *   Service    
 * @author Wang Xiaoming
 */
@Aspect
public class LoggingAspect {
	private Log log = LogFactory.getLog(this.getClass());

	@Around("execution(* com.zzvcom.sysmag.service.*Service.*(..))")
	public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
		log.info("The method " + joinPoint.getSignature().getName()
				+ " begings with " + Arrays.toString(joinPoint.getArgs()));
		try {
			Object result = joinPoint.proceed();
			log.info("The method " + joinPoint.getSignature().getName()
					+ " ends with " + result);
			return result;
		} catch (Exception e) {
			StringWriter trace = new StringWriter();
			e.printStackTrace(new PrintWriter(trace));
			log.error(trace.toString());
			throw e;
		}
	}
}

좋은 웹페이지 즐겨찾기