MVC Java Config - HandlerInterceptor not excluding paths

后端 未结 5 742
孤城傲影
孤城傲影 2021-02-07 15:37

I have a MVC Java configuration but the HandlerInterceptor is not excluding some patterns.

At the line marked with xxx, if

1) I ad

5条回答
  •  暖寄归人
    2021-02-07 16:33

    I know this was a long while ago but I just stumbled over the same problem. During my search I found the following blog. There it is mentioned that if the interceptors are configured as beans they will be automatically added to the chain. I am now using Spring 4.1.x so there might be a difference but what solved it for me was the following:

    1. (I tried to avoid defining them as a spring beans. It didn't help.)
    2. I configured the interceptors as spring beans (so I could autowire stuff into them see here)
    3. I changed my definition as follows:

      registry.addInterceptor(getMyHandlerInterceptor()) .addPathPatterns("/**") .excludePathPatterns("/user/login");

    By putting the addPathPatterns before the excludePathPatterns the behavior of the interceptor suddenly worked fine.

提交回复
热议问题