您好我正在使用ResourceUrlEncodingFilter进行版本控制,从调试我可以确认调用ResourceUrlEncodingFilter.doFilterInternal但不是ResourceUrlEncodingResponseWrapper.encodeURL,这有点奇怪。
这是我的配置:
MvcConfig(扩展WebMvcConfigurerAdapter)
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/assets/**")
.addResourceLocations("/assets/")
.setCachePeriod(31536000)
.resourceChain(true)
.addResolver(new VersionResourceResolver().addContentVersionStrategy("/**"));
}
@Bean
public ResourceUrlEncodingFilter resourceUrlEncodingFilter() {
return new ResourceUrlEncodingFilter();
}
//...and other freemarket config
的web.xml
<filter>
<filter-name>resourceUrlEncodingFilter</filter-name>
<filter-class>org.springframework.web.servlet.resource.ResourceUrlEncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>resourceUrlEncodingFilter</filter-name>
<url-pattern>/assets/*</url-pattern>
</filter-mapping>
<!-- and other config -->
ftl示例:
<link href="<@spring.url '/assets/bootstrap/css/bootstrap.min.css'/>" rel="stylesheet" type="text/css">
&#13;
结果: 当调用资产链接时,将调用ResourceUrlEncodingFilter.doFilterInternal(来自调试),但不调用ResourceUrlEncodingResponseWrapper.encodeURL。 从Chrome中,css没有版本。
我的配置是否正确?我错过了什么吗?
我使用的服务器是Wildfly 9.0.2,Spring / MVC 4.2,Spring Security 4.0.3
REF: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-config-static-resources http://www.mscharhag.com/spring/resource-versioning-with-spring-mvc