WebServer/Spring Boot
[스프링부트] AOP (Aspect Oriented Programming)
gangintheremark
2023. 9. 22. 11:00
728x90
AOP의 자세한 설명은 아래 글 참고
[Spring] AOP (Aspect Oriented Programming)
AOP 보안이나 로그, 트랜잭션과 같이 비즈니스 로직은 아니지만, 반드시 처리가 필요한 부분을 스프링에서는횡단 관심사라고 한다. AOP는 이러한 횡단 관심사를 모듈로 분리하는 프로그래밍의 패
gangintheremark.tistory.com
실습
의존성 AOP starter 패키지 등록 필수
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
@EnableAspectJAutoProxy 이용
어노테이션을 사용하는 방식이다.
@SpringBootApplication
@EnableAspectJAutoProxy
public class Application {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(Application.class, args);
}
}
@Aspect
@Component
public class BeforeAspect {
@Pointcut("execution(public String sayEcho())")
public void xxx() {
}
@Before("xxx()")
public void method() {
}
}
application.properties 이용
application.properties에 AOP 설정을 추가하는 방식이다.
# AOP
spring.aop.auto=true
728x90