인터페이스(런타임 위빙이 되기위해 필요)부터 정의해두고 

얘를 구현하는 타겟(핵심관심사항구현)클래스 구현



핵심관심사항 클래스 구현

공통관심사항 클래스 구현

위 친구들 빈으로 등록

핵심관심사항 구현 함수를 포인트컷으로 지정

공통관심사항의 각 함수를 적용시점 정보 포함에 advice지정


helloworld: 쉽게 시작하는 프로그래밍

tryhelloworld.co.kr/
기초부터 차근차근, 직접 코드를 작성해 보세요. helloworld에서는 누구나 프로그래머가 될 수 있습니다.


<aop:config>

<aop:aspect ref="myAspect">

<aop:pointcut expression="execution(public String *.doSomething())" id="myPt"/>

<!-- <aop:before method="before" pointcut-ref="myPt"/> -->

<!-- <aop:after-returning method="after_returning" pointcut-ref="myPt" returning="msg"/> -->

<!-- <aop:after-throwing method="after_throwing" pointcut-ref="myPt" throwing="th"/> -->

<!-- <aop:after method="after" pointcut-ref="myPt"/>  -->

<aop:around method="around" pointcut-ref="myPt"/>

</aop:aspect>

</aop:config>


public class MyAspect {

public void before(JoinPoint jp){

System.out.println(jp.getSignature());//AOP정보 출력

System.out.println(jp.getTarget());//핵심관심사항객체 리턴

System.out.println("");

}

public void after(JoinPoint jp){

System.out.println("");

}

public void after_returning(JoinPoint jp, String msg){

System.out.println(msg + "");

}

public void after_throwing(JoinPoint jp, Throwable th){

System.out.println(th.getMessage() + " .");

}

public void around(ProceedingJoinPoint jp){//AOP에 대한 정보를 가지고 있으면서 핵심관심사항을 수동으로 호출 시킬 수 있음

//around advice -> 핵심관심사항 전후 모두를 포함하는 advice 

//around advice에서는 직접 핵심관심사항을 호출함

try{

before(jp);

String msg = (String) jp.proceed();

after_returning(jp, msg);

}catch(Throwable e){

after_throwing(jp, e);

}

after(jp);

}

}



' IOT 기반 응용 SW과정 > Web Programing' 카테고리의 다른 글

Day61  (0) 2016.06.15
Day60 Spring-AOP  (0) 2016.06.14
Day58 AOP (Aspect Oriented Programming)  (0) 2016.06.10
Day57 MyBatis_Spring  (0) 2016.06.09
Day56 MyBatis-Spring  (0) 2016.06.08

+ Recent posts