2013-06-27 169 views
0

web.xml春天Spring MVC的安全

<web-app id="WebApp_ID" version="2.4" 
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 

    <display-name>Spring MVC Application</display-name> 
    <welcome-file-list> 
     <welcome-file>index.jsp</welcome-file> 
    </welcome-file-list> 


    <!-- Spring MVC --> 
    <servlet> 
     <servlet-name>mvc-dispatcher</servlet-name> 
     <servlet-class> 
        org.springframework.web.servlet.DispatcherServlet 
       </servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>mvc-dispatcher</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 

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

    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value> 
      /WEB-INF/mvc-dispatcher-servlet.xml, 
      /WEB-INF/spring-security.xml 
     </param-value> 
    </context-param> 

    <!-- Spring Security --> 
    <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" 
    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.1.xsd"> 

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

    <authentication-manager> 
     <authentication-provider> 
     <user-service> 
     <user name="mkyong" password="123456" authorities="ROLE_USER" /> 
     </user-service> 
     </authentication-provider> 
    </authentication-manager> 

</beans:beans> 

mvc-dispatcher-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans  
     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 

    <context:component-scan base-package="com.mkyong.common.controller" /> 

    <bean 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix"> 
     <value>/WEB-INF/pages/</value> 
     </property> 
     <property name="suffix"> 
     <value>.jsp</value> 
     </property> 
    </bean> 

</beans> 

我得到跟隨着錯誤

SEVERE:將異常發送上下文初始化事件給類的監聽器實例org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException:創建名爲'org.springframework.security.filterChainProxy'的bean時出錯: 1指定了構造函數參數,但沒有在bean'org.springframework.security.filterChainProxy'中找到匹配的構造函數(提示:指定簡單參數的索引/類型/名稱參數以避免類型歧義)

+0

你確定例外說'org.springframework.security.filterChainProxy'而不是'org.springframework.security.web.FilterChainProxy'嗎? – Dani

+0

@Dani亞其過濾器鏈代理.. –

+0

我的意思是,例外應該說'org.springframework.security.WEB.FilterChainProxy',但你寫了'org.springframework.security.filterChainProxy'。這是一個錯字嗎? – Dani

回答

0

您不需要指定mvc-dispatcher-servlet.xml contextConfiglocation

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value> 
     /WEB-INF/mvc-dispatcher-servlet.xml, 
     /WEB-INF/spring-security.xml 
    </param-value> 
</context-param> 

其溶膠你的問題