注解方式
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) ; } } }
时间: 2024-10-24 02:51:41