首页 > 代码库 > zbb20170216_spring_aop
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、知行效果图
zbb20170216_spring_aop
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。