IT/JAVA
AOP(Aspect Oriented Programming) 구현(2)
스콘_
2021. 4. 17. 17:29
반응형
2021.04.17 - [IT/Spring] - AOP(Aspect Oriented Programming)란?(1)
전 글에 이어진 내용입니다.
이번에는 스프링 AOP구현에 대해 적어보겠습니다.
구현과정
- 스프링 스프링 AOP를 사용하기 위한 의존을 추가한다.
- 공통 기능을 제공할 클래스를 구현한다.
- XML 설정 파일에 <aop:config>를 이용해서 Aspect를 설정한다. Advice를 어떤 Pointcut에 적용할지를 지정하게 된다.
XML 스키마 기반의 POJO클래스 AOP구현
Profile.java
public Object trace(ProceedingJoinPoint joinPoint)throws Throwable{
Object result = jointPoint.proceed();
}
acQuickStart.xml
<bean id="profiler" class="net.madvirus.aop.Profiler" />
<aop:config>
<aop:aspect id="traceAspect" ref="profiler">
<aop:pointcut id="publicMethod"
expression="execution(public * net.spring4.chap06..*(..))" />
<aop:around pointcut-ref="publicMethod" method="trace" />
@Aspect 애노테이션 기반 AOP퀵 스타트
ProfilingAspect.java
@Aspect
@Pointcut("execution(public * net.madvirus.board..*(..))")
private void profileTarget()
@Around("profileTarget()")
public Object trace(ProceedingJoinPoint joinPoint) throws Throwable{
joinPoint.getSignature().toShortString();
Object result = joinPoint.proceed();
acQuickStart.xml
<aop:aspectj-autoproxy />
<bean id="performanceTraceAspect"
class="net.madvirus.spring4.chap06.aop.ProfilingAspect" />