Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 弹簧3.0.5<;mvc:拦截器>;不起作用_Java_Spring_Spring Mvc_Interceptor - Fatal编程技术网

Java 弹簧3.0.5<;mvc:拦截器>;不起作用

Java 弹簧3.0.5<;mvc:拦截器>;不起作用,java,spring,spring-mvc,interceptor,Java,Spring,Spring Mvc,Interceptor,我正在尝试创建一个拦截器,以便在调用控制器之前记录http请求的详细信息。我的SpringXML是 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.

我正在尝试创建一个拦截器,以便在调用控制器之前记录http请求的详细信息。我的SpringXML是

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:tx="http://www.springframework.org/schema/tx"

xsi:schemaLocation="
    http://www.springframework.org/schema/beans     
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
                http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"
    >

<context:component-scan base-package="com.xxx.controller" />

<mvc:interceptors>
    <mvc:interceptor>
    <mvc:mapping path="/**" />
    <bean class="com.xxx.interceptor.LogBillingInterceptor">
</bean>
</mvc:interceptor>
</mvc:interceptors>
}

但它似乎不起作用。我正在使用Spring3.0.5

我刚刚看到我们正在使用spring-oauth2,并使用以下代码

<http access-denied-page="/error" access-decision-manager-ref="accessDecisionManager"  entry-point-ref="loginUrlAuthenticationEntryPoint" xmlns="http://www.springframework.org/schema/security">

    <intercept-url pattern="/oauth/token" access="IS_AUTHENTICATED_ANONYMOUSLY" />
    <intercept-url pattern="/oauth/**" access="ROLE_USER" />

    <intercept-url pattern="/store/**" access="ROLE_USER" />
    <intercept-url pattern="/balance/**" access="ROLE_USER" />
    <intercept-url pattern="/api/**" access="ROLE_USER" />
    <intercept-url pattern="/tapjoy" access="IS_AUTHENTICATED_ANONYMOUSLY" />

    <intercept-url pattern="/verify_credentials" access="ROLE_USER" />

    <intercept-url pattern="/welcome/**" access="ROLE_USER" />
    <intercept-url pattern="/logout/**" access="ROLE_USER" />

    <intercept-url pattern="/login" access="IS_AUTHENTICATED_ANONYMOUSLY" />
    <intercept-url pattern="/loginfailed" access="IS_AUTHENTICATED_ANONYMOUSLY" />

    <intercept-url pattern="/request_token_authorized.jsp" access="ROLE_USER,DENY_OAUTH" />

        <custom-filter position="FORM_LOGIN_FILTER" ref="tpAuthenticationFilter" />
</http>


我们可以添加具有Spring安全性的拦截器吗?

这可能是因为
mvc:annotation-driven
创建了handlerMapping,我看到的最佳建议是删除
mvc:annotation-driven
,替换为相应HandlerAdapter的显式bean定义(
AnnotationMethodHandlerAdapter
在3.0中),并显式指定一个
handlerMapping
作为一个属性,其中定义了拦截器


我想这对spring 3.1是有效的,我使用的是3.0.5,xml显示错误。是的,这是真的@harshit,它对3.1也无效-这个链接有一个更好的答案-怀疑它是否可能是spring Security@harshit,spring Security在DispatcherServlet通过过滤器和拦截器获得请求之前拦截在调用控制器之前执行st。
<http access-denied-page="/error" access-decision-manager-ref="accessDecisionManager"  entry-point-ref="loginUrlAuthenticationEntryPoint" xmlns="http://www.springframework.org/schema/security">

    <intercept-url pattern="/oauth/token" access="IS_AUTHENTICATED_ANONYMOUSLY" />
    <intercept-url pattern="/oauth/**" access="ROLE_USER" />

    <intercept-url pattern="/store/**" access="ROLE_USER" />
    <intercept-url pattern="/balance/**" access="ROLE_USER" />
    <intercept-url pattern="/api/**" access="ROLE_USER" />
    <intercept-url pattern="/tapjoy" access="IS_AUTHENTICATED_ANONYMOUSLY" />

    <intercept-url pattern="/verify_credentials" access="ROLE_USER" />

    <intercept-url pattern="/welcome/**" access="ROLE_USER" />
    <intercept-url pattern="/logout/**" access="ROLE_USER" />

    <intercept-url pattern="/login" access="IS_AUTHENTICATED_ANONYMOUSLY" />
    <intercept-url pattern="/loginfailed" access="IS_AUTHENTICATED_ANONYMOUSLY" />

    <intercept-url pattern="/request_token_authorized.jsp" access="ROLE_USER,DENY_OAUTH" />

        <custom-filter position="FORM_LOGIN_FILTER" ref="tpAuthenticationFilter" />
</http>