package cn.autoform.fw.config;
|
|
import cn.autoform.web.interceptor.spring.InitParamInterceptor;
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
import com.alibaba.fastjson.support.config.FastJsonConfig;
|
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
|
import org.springframework.boot.web.servlet.MultipartConfigFactory;
|
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
|
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.ContentNegotiationConfigurer;
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
import org.springframework.web.util.IntrospectorCleanupListener;
|
|
import javax.annotation.Resource;
|
import javax.servlet.MultipartConfigElement;
|
import java.nio.charset.Charset;
|
import java.util.List;
|
|
/**
|
* web 配置
|
* @author WangYX
|
*
|
*/
|
@Configuration
|
public class WebConfig extends WebMvcConfigurerAdapter{
|
|
@Resource(name="initParamInterceptor")
|
private InitParamInterceptor initParamInterceptor;
|
|
@Override
|
public void addInterceptors(InterceptorRegistry registry) {
|
InterceptorRegistration ir = registry.addInterceptor(initParamInterceptor);
|
ir.addPathPatterns("/**");
|
}
|
|
@Bean
|
public HttpMessageConverter<Object> responseBodyConverter() {
|
// StringHttpMessageConverter converter = new StringHttpMessageConverter(
|
// Charset.forName("UTF-8"));
|
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
|
FastJsonConfig fastJsonConfig = new FastJsonConfig();
|
// fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
|
//日期格式化
|
// fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
|
converter.setFastJsonConfig(fastJsonConfig);
|
return converter;
|
}
|
|
@Override
|
public void configureMessageConverters(
|
List<HttpMessageConverter<?>> converters) {
|
super.configureMessageConverters(converters);
|
converters.add(responseBodyConverter());
|
}
|
|
@Override
|
public void configureContentNegotiation(
|
ContentNegotiationConfigurer configurer) {
|
configurer.favorPathExtension(false);
|
}
|
|
@Bean
|
public MultipartConfigElement multipartConfigElement() {
|
MultipartConfigFactory factory = new MultipartConfigFactory();
|
factory.setLocation("/tmp/autoForm");
|
return factory.createMultipartConfig();
|
}
|
|
@Bean
|
public ServletListenerRegistrationBean<IntrospectorCleanupListener> serssionListenerBean(){
|
ServletListenerRegistrationBean<IntrospectorCleanupListener>
|
sessionListener = new ServletListenerRegistrationBean<>(new IntrospectorCleanupListener());
|
return sessionListener;
|
}
|
}
|