gpt4 book ai didi

java - Spring 3.0.5 not working

转载 作者:行者123 更新时间:2023-12-01 05:18:32 30 4
gpt4 key购买 nike

我正在尝试创建一个拦截器来在调用 Controller 之前记录 http 请求详细信息。我的 spring 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);

}

}

但是好像没用。我使用的是spring 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 security 添加拦截器吗?

最佳答案

这可能是因为 mvc:annotation-driven 创建的 handlerMapping,我见过的最好的建议是删除 mvc:annotation-driven,替换为适当 HandlerAdapter 的显式 bean 定义(3.0 中的 AnnotationMethodHandlerAdapter),并显式指定 handlerMapping 作为其中定义的拦截器的属性。

How to register handler interceptors with spring mvc 3.0?

关于java - Spring 3.0.5 <mvc :interceptor> not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10822488/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com