Spring Security返回404错误

时间:2018-07-29 13:43:18

标签: java spring eclipse web-applications spring-security

我正在开发一个简单的spring安全模块,但是它使用apache tomcat 9.0返回404错误,这是我的代码:

applicationContext.xml

`<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/security 
http://www.springframework.org/schema/security/spring-security-3.2.xsd
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd">

<security:user-service id="userService">
    <security:user name="user1" password="secret" authorities="ROLE_USER"/>
    <security:user name="user2" password="secret" authorities="ROLE_USER,ROLE_EDITOR"/>
</security:user-service>

<security:authentication-manager>
    <security:authentication-provider user-service-ref="userService"/>
</security:authentication-manager>

<security:http pattern="/favicon.ico" security="none"/>

<security:http auto-config="true">
    <security:intercept-url pattern="/**" access="ROLE_USER"/>
</security:http>

`

web.xml `

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">

<display-name>Archetype Created Web Application</display-name>

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

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

`

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.willey.beginningspring.ch11</groupId>
  <artifactId>spring-book-ch12</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>spring-book-ch12 Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-core</artifactId>
    <version>3.2.0.RELEASE</version>
    </dependency>

    <dependency>
      <groupId>org.springframework.security</groupId>
      <artifactId>spring-security-web</artifactId>
      <version>3.2.0.RELEASE</version>
    </dependency>

     <dependency>
      <groupId>org.springframework.security</groupId>
      <artifactId>spring-security-config</artifactId>
      <version>3.2.0.RELEASE</version>
    </dependency>

  </dependencies>
  <build>
    <finalName>spring-book-ch12</finalName>
  </build>
</project>

我的项目层次结构: enter image description here

我正在使用apache服务器9运行项目,但是却出现404错误:

原始服务器未找到目标资源的当前表示,或不愿意透露其存在

我想测试弹簧安全性,并在互联网上搜索了许多问题,但这对我没有用。帮助会得到赞赏。

0 个答案:

没有答案