实践了《指南》中的例子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的aop简单例子spring的aop简单例子spring的aop简单例子spring的aop简单例子
NULL 博文链接:https://306963591.iteye.com/blog/1129837
最近做的Spring 2.5 AOP 例子,保留下以后复习说不定用得上. 1.使用类扫描功能这个有点意思.使用时方便了许多. 2.XML配置方式
spring aop例子,这是spring aop例子哦
关于Spring的IOC和AOP的例子,帮助初学者入门。 内有bean的声明、注入;切入点和通知等功能例子。 环境配置:myeclipse, spring2.5
Spring AOP 几个不同使用方法的完整例子,使用Junit4c测试, 在我的博客上有不同配置组合的说明,可以参考
找了很久,也没在网上找到spring mvc框架下的aop例子~研究了好久终于写出来了~拿出来和大家分享一下~
Spring.net AOP 动态代理例子
内含spring ioc,aop例子,了解IOC,AOP原理
Spring3.1AOP简单例子,需要的jar包分开上传了
Spring IOC AOP MVC 简单例子
Spring中IOC/AOP的说明和例子
spring aop简单例子,入门学习的好资料
eclipse的SpringAOP和动态代理的小例子
spring aop 经典例子(原创),无论新手还是老手,可以快速对Spring AOP有个总体的认识。基于JDK1.6,Spring2.0.5,Eclipse IDE。
Spring_Aop入门例子,可以直接导入,里面有Spring需要的jar包
spring aop 通过注解实现的项目,这只是一个简单的例子。运行环境也简单。
全面讲解spring Aop 功能,例子丰富。
springAOP小例子 装配器 切入点 通知等
spring_aop的一个小例子,这个是转载哦,学习了一下,非常有用处。