0

我正在尝试使用弹簧安全

在所有配置之前

http://localhost:9090/app/login2.xhtml

请求,按我的预期工作。

我添加了一个控制器:

@Controller
@RequestMapping("/auth")
public class LoginController {


 @RequestMapping(value = "/login", method = RequestMethod.GET)
 public String getLoginPage(@RequestParam(value="error", required=false) boolean error, 
   ModelMap model) {
return "login2.xhtnml";
}

}

我在 web.xml 中有:

<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
                classpath:META-INF/spring-servlet.xml
        </param-value>
    </init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

当我打电话时使用这个配置

http://localhost:9090/app/login2.xhtml

错误来了

 WARN org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/app/login2.xhtml] in DispatcherServlet with name 'spring'

但是当我将配置映射更改为

<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>

http://localhost:9090/app/login2.xhtml按我的预期工作

http://localhost:9090/app/auth/login

没有错误,没有异常,没有重定向,我认为调度程序 servlet 无法知道这个请求。

http://localhost:9090/app/app/auth/login

<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/app/*</url-pattern>
    </servlet-mapping>

我的理解:

调度程序 servlet用作"http://localhost:9090/"搜索 login2.xhtml 和URL 的基础。"http://localhost:9090/app"/auth/login

我不知道在哪里设置它,以及为什么它们不同。

4

1 回答 1

0

您是否已将其添加SpringSecurityFilterChain到 web.xml 中?

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

如果容器启动(从日志文件),您能否通过注册的“请求绑定”?

于 2013-07-25T17:17:51.920 回答