2012-06-29 140 views
1

爲什麼當我添加春季安全 - 404錯誤

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

到我的項目它不工作,我得到:HTTP狀態404.但是,當我刪除的過濾器的依賴,它再次工作。

任何想法爲什麼?爲什麼會導致錯誤?

這裏是我的web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee  /web-app_2_5.xsd" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
version="2.5"> 


<!-- Define the basename for a resource bundle for I18N --> 
<context-param> 
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name> 
    <param-value>messages</param-value> 
</context-param> 

<context-param> 
    <param-name>contextClass</param-name> 
    <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext 
    </param-value> 

</context-param> 

<!-- Creates the Spring Container shared by all Servlets and Filters --> 
<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 
<!-- The definition of the Root Spring Container shared by all Servlets 
    and Filters --> 
<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value> 
     classpath:/META-INF/root-context.xml, 
     classpath:/META-INF/appServlet/spring-security.xml 
    </param-value> 

</context-param> 

<!-- Processes application requests --> 
<servlet> 
    <servlet-name>appServlet</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value> 
      classpath:/META-INF/appServlet/servlet-context.xml 

      </param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
    <servlet-name>appServlet</servlet-name> 
    <url-pattern>/</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> 

,這裏是我的spring_security.xml

<beans:beans xmlns="http://www.springframework.org/schema/security" 
xmlns:beans="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/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
http://www.springframework.org/schema/security 
http://www.springframework.org/schema/security/spring-security-3.0.3.xsd"> 

<security:http auto-config="true"> 
    <security:intercept-url pattern="/welcome*" access="ROLE_USER" /> 
    <security:form-login login-page="/login" default-target-url="/welcome" 
     authentication-failure-url="/loginfailed" /> 
    <security:logout logout-success-url="/logout" /> 
</security:http> 

<security:authentication-manager> 
    <security:authentication-provider> 
     <security:jdbc-user-service data-source-ref="dataSource" 

      users-by-username-query=" 
       select username,password, enabled 
       from users where USERNAME=?" 

      authorities-by-username-query=" 
       select u.username, ur.authority from users u, user_roles ur 
       where u.user_id = ur.user_id and u.username =? " 

     /> 
    </security:authentication-provider> 
</security:authentication-manager> 

    </beans:beans> 
+0

當你得到這個錯誤嗎?嘗試訪問登錄頁面或其他頁面? – jddsantaella

+0

直接將其部署到tomcat。還有所有其他頁面。 – user1067665

回答

0

嘗試改變:

<security:http auto-config="true"> 

<security:http auto-config="true" authentication-manager-ref="authManager"> 

......然後......

<security:authentication-manager> 

<security:authentication-manager id="authManager">