공통관심과 핵심관심
공통관심 : method 마다 공통으로 나타나는 로깅 예외처리 , 트랜잭션 처리 등
핵심관심 : 사용자의 요청에 따라 실제로 수행되는 business logic
공통 관심 기능을 별도로 프로그래밍 한 후 이를 적용할 핵심관심의 범위와 시점을 정의하는 프로그래밍 기법
대상객체가 인터페이스를 구현하고있는경우 : 같은 인터페이스를 구현한 다른 객체를 프록시 객체로 생성 따라서 AOP에서 참조하는 객체는 대상객체 타입이 아니다
대상객체가 인터페이스를 구현하지 않는 경우 : 대상 클래스를 상속받은 자식 클래스를 프록시 객체로 생성하고 AOP 에서 참조하는 객체는 대상객체의 타입이다 대상 클래스가 final인경우 프록시를 참조 할 수 없다.
Before Advice : 대상객체의 method 호출 전에 공통기능을 시행 <aop:before/>
<aop:after-returning/> : 대상객체의 method 호출이 정상적으로 실행된 이후 공통기능을 시행
<aop:after-throwing/> : 대상객체의 method를 실행하는 도중 예외가 발생한경우 실행
<aop:after/> : 대상객체의 method가 예외 발생 상관없이 method 실행 이후 실행
<aop:around/> : 대상객체의 method 실행 전 후 또는 예외 발생 시점에 공통기능을 실행하는데 사용
<bean id = "IAspectBean" class = ".."/>
<aop:config>
<aop:pointcut id = "loggingOP"
expression = execution(*aop.ex1.EmployeeManager.*(..))/>
//*(리턴값) . 파일경로 . 클래스명 . 함수이름 (인자)
// before
<aop:aspect id = "loggingAspect" ref = "IAspectBean">
<aop:before pointcut-ref="loggingOP" method="logBefore"/>
</aop:aspect>
//예외없이 실행이후 (after-returning)
//return값이 존재
<aop:aspect id = "loggingAspect" ref = "IAspectBean">
<aop:after-returning pointcut-ref="loggingOP" method="logAfterReturning" returning = "retVal"/>
</aop:aspect>
//예외 발생(after-throwing)
//throwing
<aop:aspect id = "loggingAspect" ref = "IAspectBean">
<aop:after-throwing pointcut-ref="loggingOP" method="logAfterThrowing" throwing = "ex"/>
</aop:aspect>
//예외있든 말든 (after)
//Joinpoint
<aop:aspect id = "loggingAspect" ref = "IAspectBean">
<aop:after pointcut-ref="loggingOP" method = "logAfrer"/>
</aop:aspect>
//예외발생 시점과 메소드 실행 전후 (around)
//proceedingjoinpoint
<aop:aspect id = "loggingAspect" ref = "IAspectBean">
<aop:around pointcut-ref="loggingOP" method="logAround" />
</aop:aspect>
</aop:config>