Spring_aop切面编程
来源:互联网 发布:php cs fixer v2.phar 编辑:程序博客网 时间:2024/05/01 16:38
1. 先建一个Man类,此具有一个name属性,并且具有两个方法(行为)qq,mm
package MAN;* 具有聊QQ和泡MM两个行为的人的对象。还有一个用户名的属性public class Man {private String name;public String getName() {return name;}public void setName(String name) {this.name = name;}public void qq(){System.out.println("QQ");}public void mm(){System.out.println("我在泡MM");}}
2.建一个FBI类
继承MethodBeforeAdvice借口
Public class FBI implements MethodBeforeAdvice(){publicvoid before(Method method, Object[] arg1, Object target) throws Throwable { // TODO Auto-generated method stub Man man = (Man)target; System.err.println("FBI发现"+man.getName()+"即将进行"+method.getName() +"活动"); } }
3.配置applicationContext.xml
<bean id="man" class="类所在路径"><property name="属性"><value type="java.lang.String">张三</value></property></bean><bean id="fbi" class="类所在路径" /><bean id="civilian"class="org.springframework.aop.framework.ProxyFactoryBean"><property name="target"><ref bean="man" /></property><property name="interceptorNames"><list><value>fbi</value></list></property></bean>
4.编写test类
package MAN;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import MAN.*;publicclass AOPTest { publicstaticvoid main(String[] args) { ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml"); Man man=(Man)ctx.getBean("civilian"); man.qq(); man.mm(); } }
运行结果:
- Spring_aop切面编程
- spring_aop
- spring_AOP
- Spring_aop
- Spring_AOP
- Spring_AOP
- Spring_Aop编程_aop概述_通知介绍
- 切面编程
- 面向切面编程
- AOP,面向切面编程
- AOP面向切面编程
- EJB中切面编程
- 面向切面编程 (AOP)
- AOP--面向切面编程
- AOP面向切面编程
- 由泛型到切面编程
- AOP面向切面编程
- 面向切面编程
- C99结构体指定初始化
- 命令模式
- 避免Android内存泄露
- LAMP配置注意事项
- sql语句增加一列
- Spring_aop切面编程
- 有关获取本机Ip地址
- js 操作JSON
- list
- 删除和空白格
- 《认知与设计——理解UI设计准则》笔记(1) 我们感知自己的期望
- XML定义
- 【iOS开发必备指南合集一】申请IDP/真机调试/GameCenter 指南/OpenFeint指南
- Telnet