Spring5源码--Spring AOP使用接口方式实现 配置xml文件

复制代码

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context-3.0.xsd

     http://www.springframework.org/schema/aop
      http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"
<!-- ==============================aop配置================================ -->
<!-- 声明一个业务类 -->
<bean id="baseCalculate" class="com.lxl.www.aop.interfaceAop.BaseCalculate"/>

<!-- 声明通知类 -->
<bean id="baseBefore" class="com.lxl.www.aop.interfaceAop.BaseBeforeAdvice"/>
<bean id="baseAfterReturn" class="com.lxl.www.aop.interfaceAop.BaseAfterReturnAdvice"/>
<bean id="baseAfterThrows" class="com.lxl.www.aop.interfaceAop.BaseAfterThrowsAdvice"/>
<bean id="baseAround" class="com.lxl.www.aop.interfaceAop.BaseAroundAdvice"/>

<!-- 指定切点匹配类 -->
<bean id="pointcut" class="com.lxl.www.aop.interfaceAop.Pointcut"/>

<!-- 包装通知,指定切点 -->
<bean id="matchBeforeAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
    <property name="pointcut">
        <ref bean="pointcut"/>
    </property>
    <property name="advice">
        <ref bean="baseBefore"/>
    </property>
</bean>

<!-- 使用ProxyFactoryBean 产生代理对象 -->
<bean id="businessProxy" class="org.springframework.aop.framework.ProxyFactoryBean">
    <!-- 代理对象所实现的接口 ,如果有接口可以这样设置 -->
    <property name="proxyInterfaces">
        <value>com.lxl.www.aop.interfaceAop.IBaseCalculate</value>
    </property>

    <!-- 设置目标对象 -->
    <property name="target">
        <ref bean="baseCalculate"/>
    </property>
    <!-- 代理对象所使用的拦截器 -->
    <property name="interceptorNames">
        <list>
            <value>matchBeforeAdvisor</value>
            <value>baseAfterReturn</value>
            <value>baseAround</value>
        </list>
    </property>
</bean>

复制代码

posted @ 2020-12-07 08:24  加菲啊  阅读(84)  评论(0编辑  收藏  举报