我有一个 Spring (3.2.2) 后端为 jQuery Mobile 前端提供静态资源。资源位于地图 /webapp/resources/images 下。此地图中已存在的资源已正确返回,但是当我添加新资源并尝试访问它(使用浏览器)时,我得到 404 not found。当我从地图中删除现有资源时,仍然可以根据请求找到它。我猜这是一些缓存问题?
web.xml
<?xml version="1.0"?>
<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">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<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>
</web-app>
mvc-调度程序-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop"
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.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>mymessages</value>
</list>
</property>
</bean>
<context:component-scan base-package="com.bvb.oiga.frontend.page.controller"/>
<context:component-scan base-package="com.bvb.oiga.dto"/>
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/, classpath:/resources/" cache-period="0" />
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="mediaTypes">
<map>
<entry key="html" value="text/html"/>
<entry key="json" value="application/json"/>
<entry key="form" value="application/x-www-form-urlencoded"/>
</map>
</property>
<property name="viewResolvers">
<list>
<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>
</list>
</property>
<property name="defaultViews">
<list>
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
</list>
</property>
</bean>
</beans>
记录:
.DispatcherServlet - Bound request context to thread: org.apache.catalina.connector.RequestFacade@d15c31
.DispatcherServlet - DispatcherServlet with name 'mvc-dispatcher' processing GET request for [/oiga-frontend/resources/images/new-logo-sm.png]
.DispatcherServlet - Testing handler map [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping@30562b] in DispatcherServlet with name 'mvc-dispatcher'
.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /resources/images/new-logo-sm.png
.mvc.method.annotation.RequestMappingHandlerMapping - Did not find handler method for [/resources/images/new-logo-sm.png]
.DispatcherServlet - Testing handler map [org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping@181ddd] in DispatcherServlet with name 'mvc-dispatcher'
.handler.BeanNameUrlHandlerMapping - No handler mapping found for [/resources/images/new-logo-sm.png]
.DispatcherServlet - Testing handler map [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@f59bb9] in DispatcherServlet with name 'mvc-dispatcher'
.handler.SimpleUrlHandlerMapping - Matching patterns for request [/resources/images/new-logo-sm.png] are [/resources/**]
.handler.SimpleUrlHandlerMapping - URI Template variables for request [/resources/images/new-logo-sm.png] are {}
.handler.SimpleUrlHandlerMapping - Mapping [/resources/images/new-logo-sm.png] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.ResourceHttpRequestHandler@1ed7b17] and 1 interceptor
.DispatcherServlet - Testing handler adapter [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter@2c304d]
.DispatcherServlet - Testing handler adapter [org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter@1172b04]
.DispatcherServlet - Last-Modified value for [/oiga-frontend/resources/images/new-logo-sm.png] is: -1
.resource.ResourceHttpRequestHandler - Trying relative path [images/new-logo-sm.png] against base location: ServletContext resource [/resources/]
.resource.ResourceHttpRequestHandler - Relative resource doesn't exist or isn't readable: ServletContext resource [/resources/images/new-logo-sm.png]
.resource.ResourceHttpRequestHandler - Trying relative path [images/new-logo-sm.png] against base location: class path resource [resources/]
.resource.ResourceHttpRequestHandler - Relative resource doesn't exist or isn't readable: class path resource [resources/images/new-logo-sm.png]
.resource.ResourceHttpRequestHandler - No matching resource found - returning 404
.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'mvc-dispatcher': assuming HandlerAdapter completed request handling
.DispatcherServlet - Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@d15c31
.DispatcherServlet - Successfully completed request
*更新:*
每次资源更新后,我都会重新加载(停止/启动)在 Eclipse Juno SR2 中运行的 apache-tomcat-7.0.32。还尝试关闭eclipse并重新启动,但没有任何运气。
父 Pom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.bvb.oiga</groupId>
<artifactId>oiga</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<spring.version>3.2.2.RELEASE</spring.version>
<java.version>1.7</java.version>
<log4j.version>1.2.16</log4j.version>
<spring.ws.version>2.0.0.RELEASE</spring.ws.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.security>3.1.3.RELEASE</spring.security>
</properties>
<modules>
<module>oiga-comtrex</module>
<module>oiga-backend-webservice</module>
<module>oiga-dto</module>
<module>oiga-frontend</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>${spring.ws.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.schema</groupId>
<artifactId>XmlSchema</artifactId>
<version>1.4.3</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.transaction</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>com.springsource.repository.bundles.release</id>
<name>SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases</name>
<url>http://repository.springsource.com/maven/bundles/release</url>
<snapshots>
<enabled>false</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
<repository>
<id>com.springsource.repository.bundles.external</id>
<name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name>
<url>http://repository.springsource.com/maven/bundles/external</url>
<snapshots>
<enabled>false</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
<repository>
<id>jboss-maven2-release-repository</id>
<url>https://repository.jboss.org/nexus/content/groups/public-jboss</url>
<snapshots>
<enabled>false</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
</repositories>
</project>
和项目pom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.bvb.oiga</groupId>
<artifactId>oiga</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>oiga-frontend</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.bvb.oiga</groupId>
<artifactId>oiga-dto</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.bvb.oiga</groupId>
<artifactId>oiga-comtrex</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.7.1</version>
</dependency>
</dependencies>
</project>