English 中文(简体)
3.1 不调用手持器窃听器
原标题:Spring 3.1 HandlerInterceptor Not being called
  • 时间:2012-05-24 21:43:37
  •  标签:
  • java
  • spring

我跟踪了手持器窃听器的文件。注意到在新版本的“春天”中,“配置的拦截器将适用于用附加说明控制器方法处理的所有请求”。

The following is in an xml configuration file: enter image description here

我有一个附加说明的控制器 开始像这样:

""https://i.sstatic.net/8FmTa.png" alt="此处输入图像描述"/"

当我要求一个执行控制器代码的URL时, 我的拦截密码从来没有被调用过。 有人能解释为什么吗?

拦截密码是:

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class DomainNameInterceptor extends HandlerInterceptorAdapter {
    public boolean preHandle(HttpServletRequest request,
                           HttpServletResponse response, Object handler) 
         throws Exception {
    System.out.println("Why is this not called?");
    return true;
  }
}

I was using the following documentation: Spring Core 3.1.x Documentation

我搜索了手持器窃听器 并效仿了包含链接内的文件里给出的榜样

最佳回答

如果您已经使用 配置了您的 MVC 上下文, 那么我认为根据此自定义名称空间定义豆类时创建的操作器映射会超越您定义的操作器映射 。 登记您的截击器的更好方式是使用 子塔来定义拦截器, 这样它就会被注册到正确的操作器映射 :

<mvc:annotation-driven>
    <mvc:interceptors>
        <ref bean="interceptor"/>
    </mvc:interceptors>
</mvc:annotation-driven>
问题回答

以上Biju s 回答正确, 除非在春季3.1 您必须这样做 :

<mvc:interceptors>
   <mvc:interceptor>
     <mvc:mapping path="/pathToIntercept/**" />
     <bean class="com.foo.bar.Interceptor" />
   </mvc:interceptor>
</mvc:interceptors>

这个问题也许很老套,但如果有人像我一样在寻找答案时碰巧碰到这个问题,下面的答复中描述的“密码”窃听器 的使用对我有效。

https://stackoverflow.com/a/35948730/1705048





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签