spring boot + security 映射 本地磁盘 静态文件 实现在线预览
- 配置文件中增加:
resources:
static-locations: file:E:\\test\\
mvc:
static-path-pattern: /files/** #改配置是请求路径 缩写
- 开放权限(本人这里是 security)
@Configuration
@Slf4j
public class InterceptorConfig extends WebMvcConfigurationSupport {
//静态资源拦截器
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
registry.addResourceHandler(" /files/** ").addResourceLocations(" file:E:\\test\\ ");
super.addResourceHandlers(registry);
}
//添加拦截器
@Override
public void addInterceptors(InterceptorRegistry registry)
{
InterceptorRegistration registration = registry.addInterceptor(new AuthIntercepter());
registration.excludePathPatterns(new String[] { "/error" });
registration.excludePathPatterns(new String[] { "/files/**" });
registration.addPathPatterns(new String[] { "/**" });
}
}
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
//接口开发
@Override
public void configure(WebSecurity web) throws Exception {
//ignore
web.ignoring()
.antMatchers("/user/listNopagging")
.antMatchers("/signature/signPc")
.antMatchers("/static/**")
.antMatchers("/files/**");
}
}
在线预览方式 http://localhost:8002/clouddo-tranning/files/osofUpload/10180/word/1.doc