Dependencies Version
Library | Version |
---|---|
org.springframework.boot:spring-boot-starter-aop | 2.4.0 |
実装例
aop.java
package com.example.aop;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class MethodStartEndAspect {
private static final Logger logger = LoggerFactory.getLogger(MethodStartEndAspect.class);
@Before("execution(* com.example..*(..))")
public void start(JoinPoint joinPoint) {
logger.info("START {}#{}", joinPoint.getSignature().getDeclaringType().getName(), joinPoint.getSignature().getName());
}
@After("execution(* com.example..*(..))")
public void end(JoinPoint joinPoint) {
logger.info("END {}#{}", joinPoint.getSignature().getDeclaringType().getName(), joinPoint.getSignature().getName());
}
}
@EnableAspectJAutoProxy
は不要。
Spring Bootに内包されているので。