merge
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package com.xwbing.configuration;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
/**
|
||||
* 说明: 程序上下文配置
|
||||
* 项目名称: sbdemo
|
||||
* 创建时间: 2017/5/10 16:36
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
@Configuration//相当于.xml文件中的<beans></beans>
|
||||
//@ComponentScan(value = {"com.xwbing"}, excludeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, value = EnableWebMvc.class)})
|
||||
//@Import(xxx.class)//用来导入其他配置类
|
||||
//@ImportResource("classpath:applicationContext.xml")//用来加载其他xml配置文件
|
||||
public class ApplicationContextConfig {
|
||||
/**
|
||||
* 线程池
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean(name = "taskExecutor")//相当于XML中的<bean></bean>
|
||||
public static ThreadPoolTaskExecutor getPoolTaskExecutor() {
|
||||
ThreadPoolTaskExecutor poolTaskExecutor = new ThreadPoolTaskExecutor();
|
||||
poolTaskExecutor.setCorePoolSize(5);//核心线程数
|
||||
poolTaskExecutor.setMaxPoolSize(1000);//最大线程数
|
||||
poolTaskExecutor.setKeepAliveSeconds(30000);//空闲线程的存活时间
|
||||
poolTaskExecutor.setQueueCapacity(200);//队列最大长度
|
||||
return poolTaskExecutor;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package com.xwbing.configuration;
|
||||
|
||||
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.web.filter.CharacterEncodingFilter;
|
||||
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 说明: 程序配置
|
||||
* 项目名称: sbdemo
|
||||
* 创建时间: 2017/5/10 16:36
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
@Configuration
|
||||
@EnableWebMvc
|
||||
//@ComponentScan(basePackages = {"com.xwbing.controller"}, includeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, value = RestController.class)})
|
||||
public class DispatcherServletConfig extends WebMvcConfigurerAdapter {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DispatcherServletConfig.class);
|
||||
|
||||
/***
|
||||
* 添加拦截器
|
||||
* @param registry
|
||||
*/
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
logger.info("addInterceptors......");
|
||||
//拦截器1:登录判断
|
||||
// registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**");
|
||||
// registry.addInterceptor(new LoginInterceptor())
|
||||
// .addPathPatterns("/**").excludePathPatterns("/user/login", "/servlet/captchaCode", "/doc.html", "/swagger-ui.html");
|
||||
//拦截器2...
|
||||
super.addInterceptors(registry);
|
||||
}
|
||||
|
||||
/**
|
||||
* 扩展消息转换器,增加fastjson
|
||||
*
|
||||
* @param converters
|
||||
*/
|
||||
@Override
|
||||
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
converters.add(getFastJsonHttpMessageConverter());
|
||||
super.configureMessageConverters(converters);
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求处理程序映射适配器,使用fastJson
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public HttpMessageConverter getFastJsonHttpMessageConverter() {
|
||||
FastJsonHttpMessageConverter httpMessageConverter = new FastJsonHttpMessageConverter();
|
||||
List<MediaType> mediaTypes = new ArrayList<>();
|
||||
mediaTypes.add(MediaType.TEXT_HTML);//避免IE出现下载JSON文件的情况
|
||||
mediaTypes.add(MediaType.APPLICATION_JSON);
|
||||
mediaTypes.add(MediaType.APPLICATION_FORM_URLENCODED);
|
||||
mediaTypes.add(MediaType.APPLICATION_OCTET_STREAM);
|
||||
httpMessageConverter.setSupportedMediaTypes(mediaTypes);
|
||||
return httpMessageConverter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件上传解析器
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public CommonsMultipartResolver getCommonsMultipartResolver() {
|
||||
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
|
||||
multipartResolver.setMaxUploadSize(104857600);
|
||||
multipartResolver.setDefaultEncoding("UTF-8");
|
||||
return multipartResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* encoding编码问题
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public Filter characterEncodingFilter() {
|
||||
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
|
||||
characterEncodingFilter.setEncoding("UTF-8");
|
||||
characterEncodingFilter.setForceEncoding(true);
|
||||
return characterEncodingFilter;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.xwbing.configuration;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
/**
|
||||
* 说明: 定时任务定时类
|
||||
* 项目名称: sbdemo
|
||||
* 创建时间: 2017/5/10 16:36
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
@Configuration
|
||||
@EnableScheduling // 启用定时任务
|
||||
public class SchedulingConfig {
|
||||
private static final Logger logger = LoggerFactory.getLogger(SchedulingConfig.class);
|
||||
|
||||
@Scheduled(cron = "0 */30 * * * ?") // 每半小时执行一次
|
||||
public void scheduler() {
|
||||
logger.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> scheduled ... ");
|
||||
//TODO
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.xwbing.configuration;
|
||||
|
||||
import com.xwbing.util.captcah.CaptchaServlet;
|
||||
import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 说明: 统一的servlet配置
|
||||
* 项目名称: sbdemo
|
||||
* 创建时间: 2017/5/10 16:36
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
@Configuration
|
||||
public class ServletConfig {
|
||||
@Bean
|
||||
public CaptchaServlet captchaServlet() {
|
||||
return new CaptchaServlet();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ServletRegistrationBean captchaServletRegistrationBean(CaptchaServlet captchaServlet) {
|
||||
ServletRegistrationBean registration = new ServletRegistrationBean(captchaServlet);
|
||||
registration.setEnabled(true);
|
||||
registration.addUrlMappings("/servlet/captchaCode");
|
||||
return registration;
|
||||
}
|
||||
/********************************************/
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.xwbing.configuration;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
/**
|
||||
* 说明: swagger config
|
||||
* 项目名称: sbdemo
|
||||
* 创建时间: 2017/5/10 16:36
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public class SwaggerConfig {
|
||||
@Bean
|
||||
public Docket createRestApi() {
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.apiInfo(apiInfo())
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("com.xwbing.controller"))
|
||||
.paths(PathSelectors.any())
|
||||
.build();
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
.title("管理系统RESTful APIs")
|
||||
.description("管理系统api接口,包含登录、注册.......")
|
||||
.termsOfServiceUrl("http://localhost:8080/swagger-ui.html")
|
||||
.contact("xiangwb")
|
||||
.version("1.0")
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user