Spring没有使用Spring Security加载CSS和js

时间:2016-12-07 19:13:58

标签: spring spring-mvc spring-security

我是Spring MVC的新手。我创建了一个包含样式和客户端验证的登录页面。在部署项目后,我看到登录页面没有任何样式和验证。我怎么解决这个问题?我提供了我的项目结构,部署描述符和弹簧配置文件。

我正在使用<mvc:resources>配置静态内容,例如img,css,js

Project Structure

  

Web .xml
     

<servlet>
    <servlet-name>spring-config</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>spring-config</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>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/application-context*.xml</param-value>
</context-param>

`

  

弹簧-CONFIG-servlet.xml中

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xsi:schemaLocation="
    http://www.springframework.org/schema/beans     
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:component-scan base-package="org.fms"/>
<mvc:annotation-driven/>
<mvc:resources mapping="/Resources**" location="/Resources/"/>


<!--View Resolver Configuration-->

<bean id="viewResolver1" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
    <property name="order" value="1"/>
    <property name="basename" value="view"/>
</bean>
<bean id="viewResolver2"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="order" value="2"/>
    <property name="prefix" value="/WEB-INF/jsp/"/>
    <property name="suffix" value=".jsp"/>
</bean>

  

应用程序的context.xml
  Application Context

1 个答案:

答案 0 :(得分:0)

感谢Srikanth

问题在于资源文件夹结构。我已将资源文件夹重组为

资源
  --css
  --js
  --images

在此更改后,我的页面正确加载。