| | |
| | | import com.ruoyi.common.config.RuoYiConfig; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.framework.interceptor.RepeatSubmitInterceptor; |
| | | import com.ruoyi.framework.interceptor.AnonymousInterceptor; |
| | | |
| | | /** |
| | | * 通用配置 |
| | |
| | | @Autowired |
| | | private RepeatSubmitInterceptor repeatSubmitInterceptor; |
| | | |
| | | @Autowired |
| | | private AnonymousInterceptor anonymousInterceptor; |
| | | |
| | | @Override |
| | | public void addResourceHandlers(ResourceHandlerRegistry registry) |
| | | { |
| | | /** 本地文件上传路径 */ |
| | | registry.addResourceHandler(Constants.RESOURCE_PREFIX + "/**") |
| | | .addResourceLocations("file:" + RuoYiConfig.getProfile() + "/"); |
| | | |
| | | /** 二维码图片访问路径 */ |
| | | registry.addResourceHandler("/qrcode/**") |
| | | .addResourceLocations("file:" + RuoYiConfig.getProfile() + "/qrcode/"); |
| | | |
| | | /** swagger配置 */ |
| | | registry.addResourceHandler("/swagger-ui/**") |
| | |
| | | } |
| | | |
| | | /** |
| | | * 自定义拦截规则 |
| | | * 添加拦截器 |
| | | */ |
| | | @Override |
| | | public void addInterceptors(InterceptorRegistry registry) |
| | | { |
| | | // 重复提交拦截器 |
| | | registry.addInterceptor(repeatSubmitInterceptor).addPathPatterns("/**"); |
| | | |
| | | // 匿名访问拦截器 |
| | | registry.addInterceptor(anonymousInterceptor).addPathPatterns("/**"); |
| | | } |
| | | |
| | | /** |
| | |
| | | public CorsFilter corsFilter() |
| | | { |
| | | CorsConfiguration config = new CorsConfiguration(); |
| | | // 设置访问源地址 |
| | | config.addAllowedOriginPattern("*"); |
| | | // 设置访问源请求头 |
| | | config.addAllowedHeader("*"); |
| | | // 设置访问源请求方法 |
| | | config.addAllowedMethod("*"); |
| | | // 有效期 1800秒 |
| | | config.setMaxAge(1800L); |
| | | // 添加映射路径,拦截一切请求 |
| | | UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); |
| | | source.registerCorsConfiguration("/**", config); |
| | | // 返回新的CorsFilter |
| | | return new CorsFilter(source); |
| | | } |
| | | } |