Spring 4.0学習ノート009——AOPの配置(XMLファイルベース)

3545 ワード

前のブログの例のファイルを借りますが、先にこれらのファイルのすべてのSpringコメントを削除してください.
前のxmlプロファイルを変更します.
<!--   Bean -->
<bean id="arithmeticCalculator" class="com.yfyzwr.spring.aop.ArithmeticCalculatorImpl"></bean>

<!--      Bean -->
<bean id="loggingAspect" class="com.yfyzwr.spring.aop.LoggingAspect"></bean>

<!--   AOP -->
<aop:config>
    <aop:pointcut expression="execution(* com.yfyzwr.spring.aop.*.*(..))" id="pointcut"/>
    <!--         -->
    <aop:aspect ref="loggingAspect" order="0">
        <aop:before method="beforeMerhod" pointcut-ref="pointcut"/>
        <aop:after method="afterMerhod" pointcut-ref="pointcut"/>
        <!--                  ,        returning  ,  returning              -->
        <aop:after-returning method="returnMerhod" pointcut-ref="pointcut" returning="result"/>
        <!--                 ,        throwing  ,  throwing              -->
        <aop:after-throwing method="throwingMerhod" pointcut-ref="pointcut" throwing="ex"/>
    </aop:aspect>
</aop:config>
前の記事の注釈に基づいてAOPを設定することがわかったら、上記のxml構成は非常に明確である.