zoukankan      html  css  js  c++  java
  • 顾问包装通知



    Interfaceadvrsor接口


    public interface Interfaceadvrsor {
    
        public void doSome();
    
    
        public void say();
    
    
    
    }
    Springadvrsor实现类
    public class Springadvrsor implements Interfaceadvrsor
    {
    
        @Override
        public void doSome() {
            System.out.println("正式业务");
        }
    
        @Override
        public void say() {
            System.out.println("无聊");
        }
    }
    SpringAopAdvice增强类
    public class SpringAopAdvice implements MethodBeforeAdvice, AfterReturningAdvice {
        @Override
        public void before(Method method, Object[] objects, Object o) throws Throwable {
            System.out.println("前者");
        }
        @Override
        public void afterReturning(Object o, Method method, Object[] objects, Object o1) throws Throwable {
            System.out.println("后者");
        }
    
    
    }

    applicationContext.xml文件

    <?xml version="1.0" encoding="UTF-8"?>
    <!--根节点是我们的beans节点-->
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
              http://www.springframework.org/schema/aop
               http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
        <bean id="springadvrsor" class="cn.spring.Springadvrsor"></bean>
        <bean id="springAopAdvice" class="cn.spring.SpringAopAdvice"></bean>
        <bean id="PointcutAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
        <property name="advice" ref="springAopAdvice"></property>
        </bean>
        <bean id="ProxyFactoryBean" class="org.springframework.aop.framework.ProxyFactoryBean">
            <property name="target" ref="springadvrsor"></property>
            <property name="interceptorNames" value="PointcutAdvisor"></property>
        </bean>
    
    </bean>

    自动顾问代理生成器

    applicationContext.xml文件

    <?xml version="1.0" encoding="UTF-8"?>
    <!--根节点是我们的beans节点-->
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
              http://www.springframework.org/schema/aop
               http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
        <bean id="springadvrsor" class="cn.spring.Springadvrsor"></bean>
        <bean id="springAopAdvice" class="cn.spring.SpringAopAdvice"></bean>
        <bean id="PointcutAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
        <property name="advice" ref="springAopAdvice"></property>
    
            <!--
            .  代表单个字符
            *   代表前一项出现0-n次
            +   代表前一项出现1-n次
            至少包含两个字符
            -->
        <property name="patterns">
            <list>
                <value>.*do.*</value>
            </list>
        </property>
        </bean>
        <!--默认顾问自动代理生成器-->
    <!--<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"></bean>-->
    </beans>

    名称顾问代理生成器

    <?xml version="1.0" encoding="UTF-8"?>
    <!--根节点是我们的beans节点-->
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
              http://www.springframework.org/schema/aop
               http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
        <bean id="springadvrsor" class="cn.spring.Springadvrsor"></bean>
        <bean id="springAopAdvice" class="cn.spring.SpringAopAdvice"></bean>
        <bean id="PointcutAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
        <property name="advice" ref="springAopAdvice"></property>
     
        <!--BeanName自动代理生成器-->
        <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
            <property name="beanNames" value="springadvrsor"></property>
            <property name="interceptorNames" value="PointcutAdvisor"></property>
        </bean>
    
    </beans>
  • 相关阅读:
    1.ok6410移植bootloader,移植u-boot,学习u-boot命令
    ok6410按键中断编程,linux按键裸机
    四. jenkins部署springboot项目(1)--window环境
    一.jenkins安装(windows环境)
    oracle服务端导出/导入方式expdp/impdp
    linux 日志文件查看
    linux kafka进程挂了 自动重启
    kafka manager遇到的一些问题
    if条件语句
    shell脚本的条件测试与比较
  • 原文地址:https://www.cnblogs.com/lowerma/p/11778547.html
Copyright © 2011-2022 走看看