Java Spring拦截器未开火

Java Spring拦截器未开火,java,spring,Java,Spring,我正试图实现这里描述的日志记录 这是处理程序映射文件: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:cont

我正试图实现这里描述的日志记录

这是处理程序映射文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:oxm="http://www.springframework.org/schema/oxm"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/oxm 
        http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd">

    <bean id="beanNameResolver" 
        class="org.springframework.web.servlet.view.BeanNameViewResolver"/>

    <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" 
    p:interceptors-ref="loggerInterceptor" />
    <context:component-scan base-package="com.audiClave.controllers" />
    <bean id="loggerInterceptor" class="com.audiClave.controllers.LoggerInterceptor" /> 

</beans>
控制台中将显示以下消息:

Mapping [/REST/en/actions] to HandlerExecutionChain with handler [com.audiClave.controllers.RestController@18f110d] and 3 interceptors
调用控制器,但不调用拦截器。 为什么不叫拦截器?我正在使用Spring3.0.5

我尝试在所有事件中设置调试断点,但没有触发任何事件。已将日志记录设置为INFO,但仍然没有输出

由于以下日志语句,正在拾取loggerInterceptor:

2011-06-22 21:11:39,828 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] INFO  org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@f2ea42: defining beans [beanNameResolver,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping#0,baseController,restController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,loggerInterceptor]; root of factory hierarchy

可能类在列表中的位置不正确???

不确定这些是否有用,但请尝试使用

  • org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping
    而不是
    DefaultAnnotationHandlerMapping
  • 替换schemaLocation以匹配您的Spring版本:

    。。。http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context/spring-context-3.0.xsd


不确定这些是否有用,但请尝试使用

  • org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping
    而不是
    DefaultAnnotationHandlerMapping
  • 替换schemaLocation以匹配您的Spring版本:

    。。。http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context/spring-context-3.0.xsd

以下工作正常:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<bean id="loggerInterceptor" class="com.audiClave.controllers.LoggerInterceptor" />
<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" 
    p:interceptors-ref="loggerInterceptor" />
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

<!-- Scans within the base package of the application for @Components to configure as beans -->
<!-- @Controller, @Service, @Configuration, etc. -->
<context:component-scan base-package="com.audiClave.controllers" />

</beans>

以下各项工作正常:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<bean id="loggerInterceptor" class="com.audiClave.controllers.LoggerInterceptor" />
<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" 
    p:interceptors-ref="loggerInterceptor" />
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

<!-- Scans within the base package of the application for @Components to configure as beans -->
<!-- @Controller, @Service, @Configuration, etc. -->
<context:component-scan base-package="com.audiClave.controllers" />

</beans>


尝试使用以下链接中提供的示例,该示例看起来与您的类似:您确定已启用记录器的信息级别吗?(a有几乎相同的代码-它正在工作)谢谢,但我将文件调整为类似的,并且仍然没有调用拦截器。请尝试使用以下链接中提供的示例,该示例与您的类似:您确定已启用记录器的信息级别吗?(a有几乎相同的代码-它正在工作)谢谢,但我将文件调整为类似的,并且仍然没有调用拦截器。