티스토리 뷰
어드바이스는 각 조인포인트에 삽입되어 동작할 횡단 관심에 해당하는 공통 기능이다.
1. before 어드바이스
- 비즈니스 메소드 실행 전 동작한다.
1 2 3 4 5 6 7 8 9 10 11 12 | <!-- applicationContext.xml --> <bean id="before" class="com.springbook.biz.common.BeforeAdvice"></bean> <aop:config> <aop:pointcut id="allPointcut" expression="execution(* com.springbook.biz..*Impl.*(..))"/> <aop:pointcut id="getPointcut" expression="execution(* com.springbook.biz..*Impl.get*(..))"/> <aop:aspect ref="before"> <aop:before pointcut-ref="allPointcut" method="beforeLog"/> </aop:aspect> </aop:config> | cs |
2. after returning 어드바이스
- 비즈니스 메소드가 성공적으로 리턴되면 동작한다.
1 2 3 4 5 6 7 8 9 10 11 12 | <!-- applicationContext.xml --> <bean id="afterReturning" class="com.springbook.biz.common.AfterReturningAdvice"></bean> <aop:config> <aop:pointcut id="allPointcut" expression="execution(* com.springbook.biz..*Impl.*(..))"/> <aop:pointcut id="getPointcut" expression="execution(* com.springbook.biz..*Impl.get*(..))"/> <aop:aspect ref="afterReturning"> <aop:after-returning pointcut-ref="getPointcut" method="afterLog"/> </aop:aspect> </aop:config> | cs |
3. after throwing 어드바이스
- 비즈니스 메소드 실행 중 예외가 발생하면 동작한다. (try~catch 블록에서 catch 블록에 해당)
1 2 3 4 5 6 7 8 9 10 11 12 | <!-- applicationContext.xml --> <bean id="afterThrowing" class="com.springbook.biz.common.AfterThrowingAdvice"></bean> <aop:config> <aop:pointcut id="allPointcut" expression="execution(* com.springbook.biz..*Impl.*(..))"/> <aop:pointcut id="getPointcut" expression="execution(* com.springbook.biz..*Impl.get*(..))"/> <aop:aspect ref="afterThrowing"> <aop:after-throwing pointcut-ref="getPointcut" method="exceptionLog"/> </aop:aspect> </aop:config> | cs |
- 강제로 예외사항을 발생시켜 준다.
1 2 3 4 5 6 7 8 | // BoardServiceImpl.java public void insertBoard(BoardVO vo) { if(vo.getSeq() == 0) { throw new IllegalArgumentException("0번 글은 등록할 수 없습니다."); } boardDAO.insertBoard(vo); } | cs |
4. after 어드바이스
- 비즈니스 메소드가 실행된 후, 무조건 실행한다. (try~catch 블록에서 finally 블록에 해당)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <!-- applicationContext.xml --> <bean id="afterThrowing" class="com.springbook.biz.common.AfterThrowingAdvice"></bean> <bean id="after" class="com.springbook.biz.common.AfterAdvice"></bean> <bean id="around" class="com.springbook.biz.common.AroundAdvice"></bean> <aop:config> <aop:pointcut id="allPointcut" expression="execution(* com.springbook.biz..*Impl.*(..))"/> <aop:pointcut id="getPointcut" expression="execution(* com.springbook.biz..*Impl.get*(..))"/> <aop:aspect ref="afterThrowing"> <aop:after-throwing pointcut-ref="getPointcut" method="exceptionLog"/> </aop:aspect> <aop:aspect ref="after"> <aop:after pointcut-ref="allPointcut" method="finallyLog"/> </aop:aspect> </aop:config> | cs |
5. around 어드바이스
- 메소드 호출 자체를 가로채 비즈니스 메소드 실행 전후에 처리할 로직을 삽입한다.
1 2 3 4 5 6 7 8 9 10 11 | <!-- applicationContext.xml --> <bean id="around" class="com.springbook.biz.common.AroundAdvice"></bean> <aop:config> <aop:pointcut id="allPointcut" expression="execution(* com.springbook.biz..*Impl.*(..))"/> <aop:pointcut id="getPointcut" expression="execution(* com.springbook.biz..*Impl.get*(..))"/> <aop:aspect ref="around"> <aop:around pointcut-ref="allPointcut" method="aroundLog"/> </aop:aspect> </aop:config> | cs |
1 2 3 4 5 6 7 8 9 10 11 12 | // AroundAdvice.java public class AroundAdvice { public Object aroundLog(ProceedingJoinPoint pjp) throws Throwable { System.out.println("[before] : 비즈니스 메소드 수행 전에 처리할 내용..."); Object returnObj = pjp.proceed(); System.out.println("[after] : 비즈니스 메소드 수행 후에 처리할 내용..."); return returnObj; } } | cs |
'spring' 카테고리의 다른 글
day2 class05 어노테이션 기반 AOP (0) | 2019.01.06 |
---|---|
day2 class04 JoinPoint와 바인드 변수 (0) | 2019.01.06 |
day2 class02 AOP용어 및 기본 설정 (0) | 2018.12.28 |
day2 class01 스프링AOP (0) | 2018.12.26 |
day1 class07 비즈니스 컴포넌트 실습2 (0) | 2018.12.25 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- @Autowired
- LoggingEvent
- java.lang.NoClassDefFoundError: org/slf4j/event/LoggingEvent
- servlet context
- ViewResolver
- preHandler
- 검색
- SqlSessionFactoryBean
- 어노테이션
- setter 인젝션
- Controller
- multiple SLF4J bindings
- 의존성
- 스프링 컨테이너
- NoClassDefFoundError
- aop
- 의존성 주입
- 횡단 관심
- JoinPoint
- exclude-mapping
- #java.lang.NoClassDefFoundError: org/slf4j/event/LoggingEvent삭제
- afterCompletion
- application context
- postHandler
- 컨트롤러
- Class path contains multiple SLF4J bindings
- handlermapping
- aspect oriented programming
- XmlWebApplicationContext
- blocking
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
글 보관함