首页 > 解决方案 > Spring MVC 自定义 url 模式

问题描述

我已经配置了 Spring Security,但它不能工作。

我的 web.xml

    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/dispatcherServlet-servlet.xml
        /WEB-INF/security-config.xml
    </param-value>
</context-param>
<servlet>
    <servlet-name>dispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>dispatcherServlet</servlet-name>
    <url-pattern>/spring/*</url-pattern>
</servlet-mapping>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- Spring Security filter -->
<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

当我定义 DispatcherServlet 的 url-pattern / 时,它工作正常。但是当我将其更改为 /spring/* 时,虽然我配置了 /* 和 /spring/* 的过滤器映射的 url-pattern ,但它无法工作

在这种情况下,我该怎么办?请告诉我

标签: springspring-mvcspring-security

解决方案


推荐阅读