You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.7 KiB
69 lines
2.7 KiB
3 years ago
|
package com.qs.serve.common.config;
|
||
|
|
||
|
import com.qs.serve.common.framework.interceptor.ApiAuthInterceptor;
|
||
|
import com.qs.serve.common.framework.interceptor.LimitSubmitInterceptor;
|
||
|
import lombok.AllArgsConstructor;
|
||
|
import org.springframework.context.annotation.Bean;
|
||
|
import org.springframework.context.annotation.Configuration;
|
||
|
import org.springframework.web.cors.CorsConfiguration;
|
||
|
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||
|
import org.springframework.web.filter.CorsFilter;
|
||
|
import org.springframework.web.multipart.MultipartResolver;
|
||
|
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
|
||
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||
|
|
||
|
/**
|
||
|
* @author YenHex
|
||
|
* @since 2022/2/24
|
||
|
*/
|
||
|
@AllArgsConstructor
|
||
|
@Configuration(proxyBeanMethods = false)
|
||
|
public class SpringMvcConfig implements WebMvcConfigurer {
|
||
|
|
||
|
private final LimitSubmitInterceptor limitSubmitInterceptor;
|
||
|
private final ApiAuthInterceptor apiAuthInterceptor;
|
||
|
|
||
|
@Override
|
||
|
public void addInterceptors(InterceptorRegistry registry) {
|
||
|
//注册LimitSubmitInterceptor拦截器
|
||
|
registry.addInterceptor(apiAuthInterceptor)
|
||
|
.addPathPatterns("/api/**")
|
||
|
.excludePathPatterns("/api/wx/login/*","/api/dev/**");
|
||
|
registry.addInterceptor(limitSubmitInterceptor)
|
||
|
.addPathPatterns("/**");
|
||
|
}
|
||
|
|
||
|
/*@Override
|
||
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||
|
registry.addResourceHandler("/static/**")
|
||
|
.addResourceLocations("classpath:/static/");
|
||
|
}*/
|
||
|
|
||
|
@Bean
|
||
|
public CorsFilter corsFilter() {
|
||
|
final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
|
||
|
final CorsConfiguration corsConfiguration = new CorsConfiguration();
|
||
|
/*是否允许请求带有验证信息*/
|
||
|
corsConfiguration.setAllowCredentials(true);
|
||
|
/*允许访问的客户端域名*/
|
||
|
corsConfiguration.addAllowedOrigin("*");
|
||
|
/*允许服务端访问的客户端请求头*/
|
||
|
corsConfiguration.addAllowedHeader("*");
|
||
|
/*允许访问的方法名,GET POST等*/
|
||
|
corsConfiguration.addAllowedMethod("*");
|
||
|
urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration);
|
||
|
return new CorsFilter(urlBasedCorsConfigurationSource);
|
||
|
}
|
||
|
|
||
|
//@Bean
|
||
|
public MultipartResolver multipartResolver(){
|
||
|
CommonsMultipartResolver resolver = new CommonsMultipartResolver();
|
||
|
resolver.setMaxInMemorySize(5120);
|
||
|
resolver.setMaxInMemorySize(300 * 1024 * 1024);
|
||
|
resolver.setDefaultEncoding("UTF-8");
|
||
|
return resolver;
|
||
|
}
|
||
|
|
||
|
}
|