2013-06-27 96 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> 

其溶胶你的问题