spring集成aspectj

阅读更多
	
	  
	
	
	


@Aspect
@Component
public class TickLogInterceptorWithAspectJ
{
    public void pointCut()
    {
    }
    
    @Around("execution(* xx..*.CarMaker.make*(..))")
    public Object tick(ProceedingJoinPoint joinPoint)
    {
        System.out.println(MessageFormat.format("enter method: {0}.{1}, params: {2}",
            joinPoint.getSignature().getDeclaringTypeName(),
            joinPoint.getSignature().getName(),
            getParamsString(joinPoint.getArgs())));
            
        try
        {
            Object o = joinPoint.proceed(joinPoint.getArgs());
            
            System.out.println(MessageFormat.format("exit method: {0}.{1}, result: {2}",
                joinPoint.getSignature().getDeclaringTypeName(),
                joinPoint.getSignature().getName(),
                o));
                
            return o;
        }
        catch (Throwable e)
        {
            return null;
        }
    }
    
    private String getParamsString(Object[] params)
    {
        return Joiner.on(",").join(Arrays.asList(params));
    }
}

你可能感兴趣的:(spring,aop,aspectj)