小编Dea*_*son的帖子

Spring 3.1 HandlerInterceptor未被调用

我按照HandlerInterceptors的文档.注意到在新版本的Spring中:"配置的拦截器将应用于使用带注释的控制器方法处理的所有请求".

以下是xml配置文件: 在此输入图像描述

我有一个带注释的控制器,像这样:

在此输入图像描述

当我请求执行控制器代码的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;
  }
}
Run Code Online (Sandbox Code Playgroud)

我使用以下文档: Spring Core 3.1.x文档

我搜索了HandlerInterceptor,并按照包含链接中的文档中给出的示例进行了操作.

java spring

7
推荐指数
2
解决办法
7936
查看次数

Tomcat 7 Restricted(ContainerServlet)错误

我一直坚持这个.我试图访问我使用HttpClient与Tomcat 7实现的ContainerServlet.我不断收到错误消息"Restricted(ContainerServlet)".我添加了基本身份验证,并尝试将其设置为内置的Host-Manager应用程序,但没有运气.

我的HostManagerServlet以:

public class HostManagerServlet
extends HttpServlet implements ContainerServlet {...
Run Code Online (Sandbox Code Playgroud)

我的web.xml包含:

<servlet>
            <servlet-name>virtualHostCreator</servlet-name>
            <servlet-class>com.eatmyfish.servlets.HostManagerServlet</servlet-class>
          </servlet>
          <servlet-mapping>
            <servlet-name>virtualHostCreator</servlet-name>
            <url-pattern>/virtualhostcreator/*</url-pattern>
          </servlet-mapping>
    <security-constraint>
        <web-resource-collection>
          <web-resource-name>HostManager commands</web-resource-name>
          <url-pattern>/virtualhostcreator/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
           <!-- NOTE:  This role is not present in the default users file -->
           <role-name>admin-script</role-name>
        </auth-constraint>
      </security-constraint>
      <security-constraint>
        <web-resource-collection>
          <web-resource-name>HTMLHostManager commands</web-resource-name>
          <url-pattern>/virtualhostcreator/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
           <!-- NOTE:  This role is not present in the default users file -->
           <role-name>admin-gui</role-name>
        </auth-constraint>
      </security-constraint>
<login-config>
    <auth-method>BASIC</auth-method>
  </login-config>
<security-role>
    <description>
      The role that is required to log in to …
Run Code Online (Sandbox Code Playgroud)

java tomcat httpclient

6
推荐指数
1
解决办法
5668
查看次数

没有定义[org.springframework.security.web.savedrequest.RequestCache]类型的限定bean

我的spring安全配置中有多个http块.从Spring Security 3.1版开始就允许这样做.当我的SpringSocial配置尝试自动注入RequestCache对象时,会发生此问题.我收到以下错误:没有定义[org.springframework.security.web.savedrequest.RequestCache]类型的限定bean:期望的单个匹配bean但找到3.如果我将Java代码中的引用删除到自动连接的RequestCache对象,在我的xml配置中有三个http块是可以的.修复此错误的最佳方法是什么?有没有办法自动装配正确的RequestCache?

xml http块:

<http pattern="/oauth/token"...>
</http>

<http pattern="/something/**...>
</http>

<http use-expressions="true"...>
</http>
Run Code Online (Sandbox Code Playgroud)

在Java Config中,有一个自动连接的RequestCache的引用:

@Bean
public ProviderSignInController providerSignInController(RequestCache requestCache) {
    return new ProviderSignInController(connectionFactoryLocator(), usersConnectionRepository(), new SimpleSignInAdapter(requestCache, userService));
} 
Run Code Online (Sandbox Code Playgroud)

这些都不会导致问题.但是,拥有多个http块和一个自动装配的RequestCache会导致:"没有定义类型[org.springframework.security.web.savedrequest.RequestCache]的限定bean:预期的单个匹配bean但找到3"

任何人都可以帮我一个正确配置的方法吗?

spring spring-security

0
推荐指数
1
解决办法
4892
查看次数

标签 统计

java ×2

spring ×2

httpclient ×1

spring-security ×1

tomcat ×1