请求的资源(/ springSecurity / hello)不可用?

时间:2016-02-09 15:15:00

标签: spring-mvc spring-security

我正在使用Spring Mvc和Spring安全性开发一个Web应用程序。 我知道这个问题是重复的,但没有一个答案解决了我的问题。

这是我的web.xml

<servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
 </servlet>


 <servlet-mapping>
    <servlet-name>springmvc</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/springmvc-servlet.xml
    </param-value>
 </context-param>


<!-- Spring Security Configuration -->


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

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

这是dispatcher Servlet

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


<context:component-scan base-package="tn.enicar.springMvc.controller" />
<mvc:annotation-driven />

<mvc:resources mapping="/resources/**" location="/resources/" />


<bean id="viewResolver"
    class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass"
        value="org.springframework.web.servlet.view.JstlView" />

    <property name="prefix">
        <value>/WEB-INF/pages/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>

<import resource="spring-security.xml" />
<import resource="applicationContext.xml" />
<mvc:default-servlet-handler />


</beans>

spring security configuration

 <?xml version="1.0" encoding="UTF-8"?>
<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.2.xsd
       http://www.springframework.org/schema/security
       http://www.springframework.org/schema/security/spring-security.xsd">


    <http  use-expressions="true" auto-config="true">
    <form-login login-page="/" default-target-url="/hello"
        authentication-failure-url="/403" />
    <intercept-url pattern="/index" access="permitAll" />
    <intercept-url pattern="/springSecurity/hello" access="isAuthenticated()" />

</http>

<beans:bean id="userService"  class="tn.enicar.springMvc.controller.UserService" />


<authentication-manager>
    <authentication-provider ref="userService">
    </authentication-provider>
</authentication-manager>
</beans:beans>

这是控制器:视图解析器

 @Controller
public class ViewResolver{

@RequestMapping(value = {"/index","/"} , method = RequestMethod.GET)
public String getLoginForm(){
    return "index";
}

@RequestMapping(value = "/403", method = RequestMethod.GET)
public ModelAndView Denied(){
    ModelAndView model= new ModelAndView();
    model.setViewName("403");
    return model;
}

@RequestMapping(value = "/hello", method = RequestMethod.GET)
public String getHello(){
    return "hello";
}

我的配置中是否缺少某些内容? 在此先感谢:)

0 个答案:

没有答案