Spring Security然后部署 - > 404错误

时间:2016-04-04 02:24:25

标签: java spring spring-mvc spring-security settings

我正在开始使用spring MVC项目。
我使用Spring安全性。

我添加了:(web.xml)

<i>


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


    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/applicationContext.xml
            /WEB-INF/security-context.xml
        </param-value>

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

    <listener>
        <listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
    </listener>



    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>

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


</web-app>



我补充说:pom.xml

<i>


    <modelVersion>4.0.0</modelVersion>
    <groupId>test4</groupId>
    <artifactId>test4</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>

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

        <!--
              SpringFramework-context
        -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.2.5.RELEASE</version>
        </dependency>


        <!--
              SpringFramework-webmvc
        -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.2.5.RELEASE</version>
        </dependency>


        <!--
            SpringFramework-webmvc portlet
        -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc-portlet</artifactId>
            <version>4.2.5.RELEASE</version>
        </dependency>


        <!--
             SpringSecurity-web
        -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>4.0.4.RELEASE</version>
        </dependency>


        <!--
             SpringSecurity-core
        -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>4.0.4.RELEASE</version>
        </dependency>


        <!--
            SpringSecurity-config
        -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>4.0.4.RELEASE</version>
        </dependency>



    </dependencies>

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/libs-snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>


    <properties>
        <javaVersion>1.8</javaVersion>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>


    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <packagingExcludes>WEB-INF/web.xml</packagingExcludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
</i>


最后添加(security-context.xml)

<br>

<i>

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

    <authentication-manager>
        <authentication-provider>
            <user-service>
                <user name="guest" password="guest" authorities="ROLE_USER"/>
            </user-service>
        </authentication-provider>
    </authentication-manager>
</beans:beans>
<./


<br>
and my folder structure is <br>
[enter image description here][1]


  [1]: http://i.stack.imgur.com/Vlzsx.png

和BUILD是成功的..
但404错误./ ..
我哪里出错了?

1 个答案:

答案 0 :(得分:0)

web.xml 中更改此行:

 <url-pattern>*.do</url-pattern>

为:

 <url-pattern>/</url-pattern>

并在 security-context.xml 中更改此内容:

<http auto-config='true'>
    <intercept-url pattern="/**" access="isAuthenticated()" />
</http>

希望得到它的帮助。