本周 Spring Framework 4.1 RC 版本发布了,现在是测试该版本新特性最好的时间,看看到底这个版本能给你的应用带来多少改进。新特性之一便是灵活的解析和转换静态 Web 资源,你可以使用 ResourceHttpRequestHandlers 来处理静态资源。
静态资源处理的流程如下:
1 2 3 4 5 6 7 8 9 10 | Resource link in a template source file
|
| Resource path (like "/css/main.css" )
v
Resolvers chain: FirstResolver, SecondResolver, ThirdResolver
(each resolver can modify the resource path or delegate to the next one)
|
| Updated resource path (like "/css/main-0e37f12.css" )
v
Resource link in a rendered template
|
新的推荐的项目文件布局:
1 2 3 4 5 6 7 8 9 10 11 12 13 | spring-app/
|- build.gradle
|- client/
| |- src/
| | |- css/
| | |- js/
| | |- main.js
| |- test /
| |- build.gradle
| |- gulpfile.js
|- server/
| |- src /main/java/
| |– build.gradle
|
应用场景:
1. 避免静态资源的缓存 2. 新的项目结构更加便于资源引用 3. 更方便的模板引擎集成 4. 完整的构建工具链
详细介绍请看官方发行说明: http://spring.io/blog/2014/07/24/spring-framework-4-1-handling-static-web-resources |