1

なぜ追加すると

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

1 に答える 1

0

変更してみてください:

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

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

...と...

<security:authentication-manager>

<security:authentication-manager id="authManager">
于 2012-10-04T06:23:58.097 に答える