码迷,mamicode.com
首页 > 编程语言 > 详细

zbb20170216_spring_aop

时间:2017-02-23 00:31:24      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:express   分享   blog   version   for   after   sch   1.0   ice   

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、知行效果图

技术分享

 

zbb20170216_spring_aop

标签:express   分享   blog   version   for   after   sch   1.0   ice   

原文地址:http://www.cnblogs.com/super-admin/p/6431386.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!