资源共享在Spring MVC App中不起作用

时间:2018-07-03 08:10:50

标签: java spring web model-view-controller resources

我创建了一个Spring MVC Web App,它运行良好。然后,我决定使UI更好,并添加了CSS文件和图像,但是没有提供它们。 如果我不在代码中添加任何CSS或图像,则该应用程序运行正常。 这是我的servlet配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    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/aop 
    http://www.springframework.org/schema/aop/spring-aop-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/beans">

<context:property-placeholder location="classpath:/database.properties"/>
<context:component-scan base-package="com.aakash.em" />
<tx:annotation-driven transaction-manager="hibernateTransactionManager" />

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

 <bean class="org.springframework.orm.hibernate3.HibernateTransactionManager" 
 id="hibernateTransactionManager">
   <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>

  <mvc:resources mapping="/resources/**" location="/resources/" cache-period="31556926" />
  <mvc:default-servlet-handler/>
</beans>

这是我的web.xml

<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 Hibernate Employee Management System</display-name>
    <servlet>
      <servlet-name>spring</servlet-name>
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/config/dispatcher-servlet.xml</param-value>
     </init-param>
     <load-on-startup>1</load-on-startup>
   </servlet>
  <servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>*.html</url-pattern>
  </servlet-mapping>
</web-app>

这是我的目录结构

enter image description here

0 个答案:

没有答案