Spring学习笔记 (六) 在Spring中使用AOP例子
来源:互联网 发布:淘宝返利机器人 编辑:程序博客网 时间:2024/05/23 05:09
实践了《指南》中的例子165页到169页,最后补充一个Action,
public class AOPMethodCostTimeAction extends ActionSupport {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
WebApplicationContext wac = this.getWebApplicationContext();
ITest dao =(ITest)wac.getBean("myAOPProxyFactory");
dao.doTest();
dao.executeTest();
return mapping.findForward("success");
}
}
具体代码已经放到gmail邮箱了。
仅仅从这个例子总结一下:
1,配置文件中需要
<!-- aop test-->
<bean id="myPointcutAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="advice">
<ref local="MyInterceptor"/>
</property>
<property name="patterns">
<list>
<value>.*do.*</value>
<value>.*execute.*</value>
</list>
</property>
</bean>
<!-- user by PointcutAdvisor -->
<bean id="MyInterceptor" class="srx.test.interceptor.MethodTimeCostInterceptor"></bean>
<!-- proxy factory user by Actoin -->
<bean id="myAOPProxyFactory" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>srx.test.interfaces.ITest</value>
</property>
<property name="target">
<ref local="test"/>
</property>
<property name="interceptorNames">
<value>myPointcutAdvisor</value>
</property>
</bean>
<!-- the dao bean be proxyed-->
<bean id="test" class="srx.test.impl.test"></bean>
2,struts-config.xml
<!-- AOP test , this is a action call two function ,and pring every method proced cost time-->
<action path="/methodcost" type="srx.test.struts.action.AOPMethodCostTimeAction">
<forward name="success" path="/WEB-INF/jsp/srx/test/aop/success.jsp"/>
</action>
使用动态代理,我本来有ITest接口,及其实现类test。以及使用test的Action。现在,我想测试test
种方法的调用时间,我需要怎么做呢?
我只需要多定义三个Bean,myPointcutAdvisor,MyInterceptor,myAOPProxyFactory。
三者的依赖关系
myAOPProxyFactory [ myPointcutAdvisor [ MyInterceptor ] ]
其中advice定义和具体的Spring advice类有关系。
待续。
- Spring学习笔记 (六) 在Spring中使用AOP例子
- Spring中使用AOP例子
- Spring AOP 学习例子
- spring框架学习(六)AOP
- spring框架学习(六)AOP
- spring框架学习(六)AOP
- spring框架学习(六)AOP
- spring框架学习(六)AOP
- spring框架学习(六)AOP
- spring框架学习(六)AOP
- spring框架学习(六)AOP
- spring框架学习(六)AOP
- spring框架学习(六)AOP
- spring框架学习(六)AOP
- spring框架学习(六)AOP
- spring框架学习(六)AOP
- [Spring]Spring AOP学习笔记(1)
- spring学习笔记: Spring AOP
- Tomcat5.5基本配置
- [免费下载 经典英文原版书] Wrox - Professional .NET Network Programming
- Delphi语句转换成批处理
- log4j Tutorials
- Linux系统一些比较经典的问题与解答
- Spring学习笔记 (六) 在Spring中使用AOP例子
- 浅析3ds max脚本
- 当你遇到以下十种人一定要珍惜
- ASP.NET 调味品:AJAX
- 几个比较好的Java代码查询网站
- Linux操作系统之系统术语简介
- C++ Template学习笔记之函数模板(6)——模板显式特化
- ADO.NET for the Object-Oriented Programmer – Part One
- 上班族"黑话"辞典大曝光