spring.mvc.static-path-pattern
代表的含义是我们应该以什么样的路径来访问静态资源,换句话说,只有静态资源满足什么样的匹配条件,Spring Boot才会处理静态资源请求。
spring.resources.static-locations
用于告诉Spring Boot应该在何处查找静态资源文件,这是一个列表性的配置,查找文件时会依赖于配置的先后顺序依次进行。
spring:application:name: testservlet:multipart:max-file-size: 500MBmax-request-size: 500MBmvc:static-path-pattern: /material/**resources:static-locations: file:/opt/oa/enclosure/dispatch,file:/home/versioncn:chinaunicom:dispatchEnclosurePath: /opt/oa/enclosure/dispatchmaterialLink: http://10.163.76.160:9010/form/material/
配置以上属性,然后将一个图片(例如:1.jpg)和文档(例如:1.doc)放置到服务器/opt/oa/enclosure/dispatch或/home/version目录下,通过项目名http://10.163.76.160:9010/form/material/1.jpg进行在线打开图片,通过项目名http://10.163.76.160:9010/form/material/1.doc进行在线下载文档。
如果被拦截器拦截访问失败情况下选用
@Configurationpublic class LoggerWebAppConfig extends WebMvcConfigurationSupport {@Autowiredprivate LoggerInterceptor interceptor;@Overridepublic void addInterceptors(InterceptorRegistry registry) {// 拦截url配置//registry.addInterceptor(interceptor).addPathPatterns("/**");// 排除url配置registry.addInterceptor(interceptor).excludePathPatterns("/**/get**");}@Overridepublic void addResourceHandlers(ResourceHandlerRegistry registry) {registry.addResourceHandler("/material/**").addResourceLocations("file:/D://enclosure/img/","file:/D://enclosure/app/");super.addResourceHandlers(registry);}}