首页 > 代码库 > spring aop配置

spring aop配置

注解方式

applicationContext.xml 加入下面配置

<!--Spring Aop 启用自动代理注解 -->
<aop:aspectj-autoproxy proxy-target-class="true"/>

LoggingAspect,java

package com.lingdong.spring.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Order(1)
@Component
@Aspect
public class LoggingAspect {
    private final static Logger logger = LoggerFactory.getLogger(LoggingAspect.class);
    @Pointcut("execution(* com.lingdong.spring.aop.*(..))")
    public void aspect(){}
    @Before("aspect()")
    public void before(JoinPoint joinPoint){
        if (logger.isInfoEnabled()){
            logger.info("before:"+joinPoint) ;
        }
    }
}


本文出自 “Java技术博客” 博客,请务必保留此出处http://lingdong.blog.51cto.com/3572216/1888669

spring aop配置