5.5.6 Advisors by sh

5.5.6. Advisors

"advisors"의 개념은 스프링에서 정의한 AOP 지원에서 비롯된 것이며 AspectJ와 직접적으로 동일하지는 않습니다. advisor는 advice가 하나 뿐인 작지만 자립적인 aspect와 같습니다. advice 자체는 bean으로 표현되며 Advice Types in Spring에 설명 된 advice 인터페이스 중 하나를 구현해야합니다. advisor는 AspectJ pointcut 표현식을 이용할 수있습니다.

Advisor = 1개의 Advice + 1개의 Pointcut

하나의 짝으로 사용할 때.. 포인트 컷을 재사용하지 않을 때

스프링은 <aop:advisor>요소로 advisor 개념을 지원한다. 가장 일반적으로 트랜잭션 어드바이스와 함께 사용되는 것을 볼 수 있습니다. 트랜잭션 어드바이스는 스프링에서 자체 네임 스페이스를 지원합니다. 다음 예에서는 advisor를 보여줍니다.

<aop:config>

    <aop:pointcut id="businessService"
        expression="execution(* com.xyz.myapp.service.*.*(..))"/>

    <aop:advisor
        pointcut-ref="businessService"
        advice-ref="tx-advice"/>

</aop:config>

<tx:advice id="tx-advice">
    <tx:attributes>
        <tx:method name="*" propagation="REQUIRED"/>
    </tx:attributes>
</tx:advice>

앞의 예제에서 사용한 pointcut-ref 속성뿐만 아니라 pointcut속성을 사용하여 pointcut 표현식을 inline으로 정의 할 수도 있습니다.

advice가 ordering에 참여할 수 있도록 advisor의 우선 순위를 정의하려면 order속성을 사용하여 advisor의 Ordered값을 정의하십시오.

Last updated