package com.cjh.aop2;
/**
* @author Caijh
*
* 2017年7月11日 下午3:53:19
*/
public class BraveKnight {
public void saying(){
System.out.println("我是骑士");
}
}
package com.cjh.aop2;
/**
* @author Caijh
*
* 2017年7月11日 下午3:47:04
*/
public class Minstrel {
public void beforSay(){
System.out.println("前置通知");
}
public void afterSay(){
System.out.println("后置通知");
}
}
<?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.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd"> <!-- 目标对象 --> <bean id="knight" class="com.cjh.aop2.BraveKnight"/> <!-- 切面bean --> <bean id="mistrel" class="com.cjh.aop2.Minstrel"/> <!-- 面向切面编程 --> <aop:config> <aop:aspect ref="mistrel"> <!-- 定义切点 --> <aop:pointcut expression="execution(* *.saying(..))" id="embark"/> <!-- 声明前置通知 (在切点方法被执行前调用)--> <aop:before method="beforSay" pointcut-ref="embark"/> <!-- 声明后置通知 (在切点方法被执行后调用)--> <aop:after method="afterSay" pointcut-ref="embark"/> </aop:aspect> </aop:config> </beans>
package com.cjh.aop2;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author Caijh
*
* 2017年7月11日 下午4:02:04
*/
public class Test {
public static void main(String[] args) {
ApplicationContext ac = new ClassPathXmlApplicationContext("com/cjh/aop2/beans.xml");
BraveKnight br = (BraveKnight) ac.getBean("knight");
br.saying();
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有