浏览 3494 次
锁定老帖子 主题:spring环绕通知无法拦截指定方法
该帖已经被评为新手帖
|
|
---|---|
作者 | 正文 |
发表时间:2007-11-14
/** * */ package com.hinge.bi.taglib; /** * @author */ import java.util.List; import javax.servlet.jsp.JspTagException; import javax.servlet.jsp.tagext.TagSupport; import com.hinge.bi.service.explorer.ResourceServiceI; import com.hinge.bi.service.taglib.TagLibServiceI; import com.hinge.bi.service.useradmin.UserServiceI; public class UserExploreList extends TagSupport { public UserExploreList() { super(); } public int doStartTag() throws JspTagException { System.out.println( "Hello Sunning "); return EVAL_BODY_INCLUDE; } public int doEndTag() throws JspTagException { return EVAL_PAGE; } } 以下是spring 的环绕通知代码 ----------------------------------------------- package com.hinge.bi.taglib.aop; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import com.hinge.bi.service.explorer.ResourceServiceI; import com.hinge.bi.service.useradmin.UserServiceI; public class PurviewInspect implements MethodInterceptor { private UserServiceI userService; private ResourceServiceI resourceService; public void setResourceService(ResourceServiceI resourceService) { this.resourceService = resourceService; } public void setUserService(UserServiceI userService) { this.userService = userService; } public Object invoke(MethodInvocation invocation) throws Throwable { System.out.println( "Hello Sunnning "); HttpServletRequest request = (HttpServletRequest) invocation.getArguments()[2]; HttpServletResponse response=(HttpServletResponse) invocation.getArguments()[3]; String method=request.getParameter( "action "); if (true) { response.sendRedirect( "/hingebi/control/login.jsp "); return null; } Object result = invocation.proceed(); // 调用MyBuyBook中的buyBook方法,即真实操作 return result; } } 以下是spring中的配置 <?xml version= "1.0 "?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN " "http://www.springframework.org/dtd/spring-beans.dtd "> <beans> <bean id= "userExploreList " class= "com.hinge.bi.taglib.UserExploreList "> </bean> <!-- advice配置--> <bean id= "explorePurviewInspect " class= "com.hinge.bi.taglib.aop.PurviewInspect "> <property name= "userService "> <ref bean= "userService " /> </property> <property name= "resourceService "> <ref bean= "resourceService " /> </property> </bean> <bean id= "explorePurviewInspectAdvisor " class= "org.springframework.aop.support.NameMatchMethodPointcutAdvisor "> <property name= "mappedName " value= "doStartTag "> </property> <property name= "advice " ref= "explorePurviewInspect "> </property> </bean> <!-- 装配advisor--> <bean id= "theAdvisor " class= "org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator "> <property name= "beanNames "> <value> userExploreList </value> </property> <property name= "interceptorNames "> <list> <value> explorePurviewInspectAdvisor </value> </list> </property> </bean> </beans> 但是在运行含有该标签的jsp时,总是直接就运行doStartTag方法了,spring没有起到拦截的作用。。 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2007-11-15
你的标签又不是在Spring的上下文环境当中创建出来的,Spring怎么能拦截到它呢
|
|
返回顶楼 | |
发表时间:2007-11-15
必须以bean的形式出现在bean-config 中?才可拦截?
|
|
返回顶楼 | |
发表时间:2007-11-17
我知道了 谢谢colin4k
http://www.iteye.com/topic/40553 http://www.iteye.com/topic/47879 解决。 |
|
返回顶楼 | |