• zbb20170216_spring_aop


    1、总体结构图

    2、class文件

    MyLog.java
    package com.zbb.aop;
    
    import com.sun.xml.internal.bind.v2.schemagen.xmlschema.List;
    
    public class MyLog {
        public void printBefore() {
            
            System.out.println("printBefore");
        }
        public void printAfter() {
            System.out.println("printAfter");
        }
    }

    MyPoint.java

    package com.zbb.aop;
    
    public interface MyPoint {
        public void save();
    }

    MyPointImp.java

    package com.zbb.aop;
    
    public class MyPointImp implements MyPoint{
    
        public void save() {
            System.out.println("save");
        }
    
    
    }

    MyTest.java

    package com.zbb.aop;
    
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    public class MyTest {
        public static void main(String[] args) {
            ClassPathXmlApplicationContext bean = new ClassPathXmlApplicationContext("applicationContext.xml");
            MyPoint obj = (MyPoint)bean.getBean("ponit");
            obj.save();
            
        }
    }

    3、配置文件

    applicationContext.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <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"
        xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
    
        <bean id="myAop" class="com.zbb.aop.MyLog"></bean>
        
        <bean id="ponit" class="com.zbb.aop.MyPointImp"></bean>
        <aop:config>
            <aop:aspect id="myAspect" ref="myAop">
                <aop:pointcut id="businessService" expression="execution(* *.save(..))" />
                <aop:before pointcut-ref="businessService" method="printBefore" />
                <aop:after pointcut-ref="businessService" method="printAfter" />
            </aop:aspect>
        </aop:config>
    
    
    </beans>

    4、知行效果图

  • 相关阅读:
    JUC高并发编程(三)之模拟接口压力测试
    JUC高并发编程(二)之多线程下载支付宝对账文件
    JUC高并发编程(一)之请求合并案例
    《Head First设计模式》读书笔记
    图文详解23种设计模式
    Laravel路由匹配
    深夜debug:一个不常遇到的HbuilderX自动化测试运行问题
    高德地图API中折线polyline不能跨越180度经度线的解决方案
    sublime配置java运行环境
    Docker技术入门
  • 原文地址:https://www.cnblogs.com/super-admin/p/6431386.html
Copyright © 2020-2023  润新知