|
|
|
@ -1,56 +1,77 @@
|
|
|
|
|
/*
|
|
|
|
|
* The MIT License (MIT)
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2014-2016 abel533@gmail.com
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
* THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package com.jingcheng.archives.config;
|
|
|
|
|
package com.jingcheng.cms.conf;
|
|
|
|
|
|
|
|
|
|
import com.jingcheng.cms.constants.AppConstant;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.boot.web.servlet.MultipartConfigFactory;
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.http.converter.HttpMessageConverter;
|
|
|
|
|
import org.springframework.http.converter.StringHttpMessageConverter;
|
|
|
|
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
|
|
|
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
|
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
|
|
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
|
|
|
|
|
|
|
|
|
import java.nio.charset.Charset;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import javax.servlet.MultipartConfigElement;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 配置中文支持
|
|
|
|
|
*
|
|
|
|
|
* @author
|
|
|
|
|
* @since 2015-12-19 16:16
|
|
|
|
|
*/
|
|
|
|
|
@Configuration
|
|
|
|
|
public class WebMvcConfig extends WebMvcConfigurationSupport {
|
|
|
|
|
public class WebMvcConfig extends WebMvcConfigurerAdapter {
|
|
|
|
|
@Value("${oss.maxFileSize}")
|
|
|
|
|
private String maxFileSize;
|
|
|
|
|
@Value("${oss.maxRequestSize}")
|
|
|
|
|
private String maxRequestSize;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//解决跨域问题
|
|
|
|
|
@Override
|
|
|
|
|
public void addCorsMappings(CorsRegistry registry) {
|
|
|
|
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
|
|
|
registry.addResourceHandler("/js/**").addResourceLocations("classpath:/js/");
|
|
|
|
|
registry.addResourceHandler("swagger-ui.html")
|
|
|
|
|
.addResourceLocations("classpath:/META-INF/resources/");
|
|
|
|
|
registry.addResourceHandler("/webjars/**")
|
|
|
|
|
.addResourceLocations("classpath:/META-INF/resources/webjars/");
|
|
|
|
|
registry.addResourceHandler(AppConstant.FILE_MAP)
|
|
|
|
|
.addResourceLocations("file:" + AppConstant.FILE_PATH);
|
|
|
|
|
|
|
|
|
|
registry.addMapping("/**")
|
|
|
|
|
.allowedOrigins("*")
|
|
|
|
|
.allowCredentials(true)
|
|
|
|
|
.allowedMethods("GET", "POST", "DELETE", "PUT")
|
|
|
|
|
.maxAge(3600);
|
|
|
|
|
super.addResourceHandlers(registry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 文件上传配置
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Bean
|
|
|
|
|
public HttpMessageConverter<String> responseBodyConverter() {
|
|
|
|
|
StringHttpMessageConverter converter = new StringHttpMessageConverter(
|
|
|
|
|
Charset.forName("UTF-8"));
|
|
|
|
|
return converter;
|
|
|
|
|
public MultipartConfigElement multipartConfigElement() {
|
|
|
|
|
MultipartConfigFactory factory = new MultipartConfigFactory();
|
|
|
|
|
// 单个数据大小
|
|
|
|
|
factory.setMaxFileSize(maxFileSize);
|
|
|
|
|
/// 总上传数据大小
|
|
|
|
|
factory.setMaxRequestSize(maxRequestSize);
|
|
|
|
|
return factory.createMultipartConfig();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
|
|
|
|
super.configureMessageConverters(converters);
|
|
|
|
|
converters.add(responseBodyConverter());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//WebMvcConfigurer时,将springboot的默认配置覆盖,默认配置中配置过资源解析,所以访问不到swagger
|
|
|
|
|
@Override
|
|
|
|
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
|
|
|
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
|
|
|
|
|
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|