1

コントローラへの呼び出しが発生する前に、httpリクエストの詳細をログに記録するインターセプターを作成しようとしています。私の春のxmlは

<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>

私のインターセプタークラス

public class LogBillingInterceptor extends HandlerInterceptorAdapter{

@Override
public boolean preHandle(HttpServletRequest request,
        HttpServletResponse response, Object handler) throws Exception {
    System.out.println("sdfsdfdsfd");
    return super.preHandle(request, response, handler);
}

@Override
public void postHandle(HttpServletRequest request,
        HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    System.out.println("aaaaaaaasdfsdfdsfd");
    super.postHandle(request, response, handler, modelAndView);
}

@Override
public void afterCompletion(HttpServletRequest request,
        HttpServletResponse response, Object handler, Exception ex)
        throws Exception {
    System.out.println("qqqqqqqqqqsdfsdfdsfd");
    super.afterCompletion(request, response, handler, ex);

}

}

しかし、それは機能していないようです。スプリング3.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セキュリティでインターセプターを追加できますか?

4

1 に答える 1

0

によって作成された handlerMapping が原因である可能性があります。mvc:annotation-driven私が見た最良の推奨事項は、 を削除mvc:annotation-drivenし、適切な HandlerAdapter( AnnotationMethodHandlerAdapterin 3.0)の明示的な Bean 定義に置き換え、handlerMappingそこで定義されたインターセプターを使用してプロパティとして a を明示的に指定することです。

spring mvc 3.0でハンドラーインターセプターを登録するには?

于 2012-05-30T19:01:13.473 に答える