spring interceptor is never called

自作多情 提交于 2019-12-23 12:16:32

问题


I have the following interceptor:

@Component
public class ExternalLinkInterceptor extends HandlerInterceptorAdapter {

    private static final Logger logger = Logger.getLogger(ExternalLinkInterceptor.class);

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        logger.info("preHandle ~ invoked");
}
}

it is supposed to intercept before request handle to the following controller method:

@Controller
@PreAuthorize("isAuthenticated()")
@RequestMapping("/assay/process")
public class VariantPrioritizationsController extends AssayBaseController{

    private static final Logger logger = Logger.getLogger(VariantPrioritizationsController.class);
@RequestMapping("/openAnalyticalProjectForAssay")
    public ModelAndView openAnalyticalProjectForAssay(HttpSession session,@RequestParam(value = "analyticalProjId", required=true)String projectId) throws PanDaApplicationException{
    //code 
     }
}

this is the interceptor declaration in the spring-servlet.xml:

<mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/assay/process/openAnalyticalProjectForAssay*"/>
            <beans:bean class="com.syngenta.panda.web.mvc.interceptor.ExternalLinkInterceptor"/>
        </mvc:interceptor>
    </mvc:interceptors>

now my interceptor is never invoked and I don't know why?! any help


回答1:


Please try updating the mvc:mapping path to:

<mvc:mapping path="/assay/process/**" />



回答2:


The configuration for the mvc:interceptor doesn't look correct to me. I have used the locale change interceptors before from Spring and their configuration is very simple:

<mvc:interceptors>
    <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" p:paramName="language"/>
</mvc:interceptors>

This interceptor just looks for a param on the URL to change the locale that the user has selected.

This video walks through the setup of everything including the locale interceptor:

http://pluralsight.com/training/Courses/TableOfContents/springmvc-intro



来源:https://stackoverflow.com/questions/16547972/spring-interceptor-is-never-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!