update 配置转移到 yml 文件 统一管理

This commit is contained in:
疯狂的狮子li 2021-05-11 10:02:32 +08:00
parent 961c60dd1a
commit dafdb43c84
6 changed files with 112 additions and 51 deletions

View File

@ -21,32 +21,54 @@ import java.util.List;
/** /**
* Swagger2的接口配置 * Swagger2的接口配置
* *
* @author ruoyi * @author Lion Li
*/ */
@Configuration @Configuration
@EnableSwagger2WebMvc @EnableSwagger2WebMvc
@EnableKnife4j @EnableKnife4j
public class SwaggerConfig public class SwaggerConfig {
{ /**
/** 系统基础配置 */ * 系统基础配置
*/
@Autowired @Autowired
private RuoYiConfig ruoyiConfig; private RuoYiConfig ruoyiConfig;
/** 是否开启swagger */ /**
* 是否开启swagger
*/
@Value("${swagger.enabled}") @Value("${swagger.enabled}")
private boolean enabled; private boolean enabled;
/** 设置请求的统一前缀 */ /**
* 设置请求的统一前缀
*/
@Value("${swagger.pathMapping}") @Value("${swagger.pathMapping}")
private String pathMapping; private String pathMapping;
/**
* 标题
*/
@Value("${swagger.title}")
private String title;
/**
* 描述
*/
@Value("${swagger.description}")
private String description;
/**
* 版本
*/
@Value("${swagger.version}")
private String version;
/** /**
* 创建API * 创建API
*/ */
@Bean @Bean
public Docket createRestApi() public Docket createRestApi() {
{
return new Docket(DocumentationType.SWAGGER_2) return new Docket(DocumentationType.SWAGGER_2)
// 是否启用Swagger // 是否启用Swagger
.enable(enabled) .enable(enabled)
@ -70,8 +92,7 @@ public class SwaggerConfig
/** /**
* 安全模式这里指定token通过Authorization头请求头传递 * 安全模式这里指定token通过Authorization头请求头传递
*/ */
private List<ApiKey> securitySchemes() private List<ApiKey> securitySchemes() {
{
List<ApiKey> apiKeyList = new ArrayList<ApiKey>(); List<ApiKey> apiKeyList = new ArrayList<ApiKey>();
apiKeyList.add(new ApiKey("Authorization", "Authorization", "header")); apiKeyList.add(new ApiKey("Authorization", "Authorization", "header"));
return apiKeyList; return apiKeyList;
@ -80,8 +101,7 @@ public class SwaggerConfig
/** /**
* 安全上下文 * 安全上下文
*/ */
private List<SecurityContext> securityContexts() private List<SecurityContext> securityContexts() {
{
List<SecurityContext> securityContexts = new ArrayList<>(); List<SecurityContext> securityContexts = new ArrayList<>();
securityContexts.add( securityContexts.add(
SecurityContext.builder() SecurityContext.builder()
@ -94,8 +114,7 @@ public class SwaggerConfig
/** /**
* 默认的安全上引用 * 默认的安全上引用
*/ */
private List<SecurityReference> defaultAuth() private List<SecurityReference> defaultAuth() {
{
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything"); AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
authorizationScopes[0] = authorizationScope; authorizationScopes[0] = authorizationScope;
@ -107,18 +126,17 @@ public class SwaggerConfig
/** /**
* 添加摘要信息 * 添加摘要信息
*/ */
private ApiInfo apiInfo() private ApiInfo apiInfo() {
{
// 用ApiInfoBuilder进行定制 // 用ApiInfoBuilder进行定制
return new ApiInfoBuilder() return new ApiInfoBuilder()
// 设置标题 // 设置标题
.title("标题若依管理系统_接口文档") .title(title)
// 描述 // 描述
.description("描述:用于管理集团旗下公司的人员信息,具体包括XXX,XXX模块...") .description(description)
// 作者信息 // 作者信息
.contact(new Contact(ruoyiConfig.getName(), null, null)) .contact(new Contact(ruoyiConfig.getName(), null, null))
// 版本 // 版本
.version("版本号:" + ruoyiConfig.getVersion()) .version(version)
.build(); .build();
} }
} }

View File

@ -119,6 +119,7 @@ token:
# MyBatis配置 # MyBatis配置
# https://baomidou.com/config/ # https://baomidou.com/config/
mybatis-plus: mybatis-plus:
mapperPackage: com.ruoyi.**.mapper
# 对应的 XML 文件位置 # 对应的 XML 文件位置
mapperLocations: classpath*:mapper/**/*Mapper.xml mapperLocations: classpath*:mapper/**/*Mapper.xml
# 实体扫描多个package用逗号或者分号分隔 # 实体扫描多个package用逗号或者分号分隔
@ -217,6 +218,12 @@ swagger:
enabled: true enabled: true
# 请求前缀 # 请求前缀
pathMapping: /dev-api pathMapping: /dev-api
# 标题
title: '标题RuoYi-Vue-Plus后台管理系统_接口文档'
# 描述
description: '描述:用于管理集团旗下公司的人员信息,具体包括XXX,XXX模块...'
# 版本
version: '版本号: ${ruoyi-vue-plus.version}'
# 防止XSS攻击 # 防止XSS攻击
xss: xss:
@ -227,7 +234,26 @@ xss:
# 匹配链接 # 匹配链接
urlPatterns: /system/*,/monitor/*,/tool/* urlPatterns: /system/*,/monitor/*,/tool/*
threadPoolConfig:
# 是否开启线程池
enabled: false
# 核心线程池大小
corePoolSize: 8
# 最大可创建的线程数
maxPoolSize: 16
# 队列最大长度
queueCapacity: 128
# 线程池维护线程所允许的空闲时间
keepAliveSeconds: 300
# 线程池对拒绝任务(无线程可用)的处理策略
# CallerRunsPolicy 等待
# DiscardOldestPolicy 放弃最旧的
# DiscardPolicy 丢弃
# AbortPolicy 中止
rejectedExecutionHandler: CallerRunsPolicy
feign: feign:
package: com.ruoyi.**.feign
# 开启压缩 # 开启压缩
compression: compression:
request: request:

View File

@ -1,30 +1,26 @@
package com.ruoyi.framework.config; package com.ruoyi.framework.config;
import java.util.TimeZone;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.context.annotation.EnableAspectJAutoProxy;
import java.util.TimeZone;
/** /**
* 程序注解配置 * 程序注解配置
* *
* @author ruoyi * @author Lion Li
*/ */
@Configuration @Configuration
// 表示通过aop框架暴露该代理对象,AopContext能够访问 // 表示通过aop框架暴露该代理对象,AopContext能够访问
@EnableAspectJAutoProxy(exposeProxy = true) @EnableAspectJAutoProxy(exposeProxy = true)
// 指定要扫描的Mapper类的包的路径 public class ApplicationConfig {
@MapperScan("com.ruoyi.**.mapper")
public class ApplicationConfig
{
/** /**
* 时区配置 * 时区配置
*/ */
@Bean @Bean
public Jackson2ObjectMapperBuilderCustomizer jacksonObjectMapperCustomization() public Jackson2ObjectMapperBuilderCustomizer jacksonObjectMapperCustomization() {
{
return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder.timeZone(TimeZone.getDefault()); return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder.timeZone(TimeZone.getDefault());
} }
} }

View File

@ -19,7 +19,7 @@ import java.util.concurrent.TimeUnit;
* *
* @author Lion Li * @author Lion Li
*/ */
@EnableFeignClients("com.ruoyi.**.feign") @EnableFeignClients("${feign.package}")
@Configuration @Configuration
@ConditionalOnClass(Feign.class) @ConditionalOnClass(Feign.class)
@AutoConfigureBefore(FeignAutoConfiguration.class) @AutoConfigureBefore(FeignAutoConfiguration.class)

View File

@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.ruoyi.framework.mybatisplus.CreateAndUpdateMetaObjectHandler; import com.ruoyi.framework.mybatisplus.CreateAndUpdateMetaObjectHandler;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
@ -17,6 +18,8 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
*/ */
@EnableTransactionManagement(proxyTargetClass = true) @EnableTransactionManagement(proxyTargetClass = true)
@Configuration @Configuration
// 指定要扫描的Mapper类的包的路径
@MapperScan("${mybatis-plus.mapperPackage}")
public class MybatisPlusConfig { public class MybatisPlusConfig {
@Bean @Bean

View File

@ -1,44 +1,65 @@
package com.ruoyi.framework.config; package com.ruoyi.framework.config;
import java.util.concurrent.ScheduledExecutorService; import com.ruoyi.common.utils.Threads;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor;
import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import com.ruoyi.common.utils.Threads;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor;
/** /**
* 线程池配置 * 线程池配置
* *
* @author ruoyi * @author Lion Li
**/ **/
@Configuration @Configuration
public class ThreadPoolConfig public class ThreadPoolConfig {
{
// 核心线程池大小 // 核心线程池大小
private int corePoolSize = 50; @Value("${threadPoolConfig.corePoolSize}")
private int corePoolSize;
// 最大可创建的线程数 // 最大可创建的线程数
private int maxPoolSize = 200; @Value("${threadPoolConfig.maxPoolSize}")
private int maxPoolSize;
// 队列最大长度 // 队列最大长度
private int queueCapacity = 1000; @Value("${threadPoolConfig.queueCapacity}")
private int queueCapacity;
// 线程池维护线程所允许的空闲时间 // 线程池维护线程所允许的空闲时间
private int keepAliveSeconds = 300; @Value("${threadPoolConfig.keepAliveSeconds}")
private int keepAliveSeconds;
// 线程池对拒绝任务(无线程可用)的处理策略
@Value("${threadPoolConfig.rejectedExecutionHandler}")
private String rejectedExecutionHandler;
@Bean(name = "threadPoolTaskExecutor") @Bean(name = "threadPoolTaskExecutor")
public ThreadPoolTaskExecutor threadPoolTaskExecutor() @ConditionalOnProperty(prefix = "threadPoolTaskExecutor", name = "enabled", havingValue = "true")
{ public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setMaxPoolSize(maxPoolSize); executor.setMaxPoolSize(maxPoolSize);
executor.setCorePoolSize(corePoolSize); executor.setCorePoolSize(corePoolSize);
executor.setQueueCapacity(queueCapacity); executor.setQueueCapacity(queueCapacity);
executor.setKeepAliveSeconds(keepAliveSeconds); executor.setKeepAliveSeconds(keepAliveSeconds);
// 线程池对拒绝任务(无线程可用)的处理策略 RejectedExecutionHandler handler;
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); if (rejectedExecutionHandler.equals("CallerRunsPolicy")) {
handler = new ThreadPoolExecutor.CallerRunsPolicy();
} else if (rejectedExecutionHandler.equals("DiscardOldestPolicy")) {
handler = new ThreadPoolExecutor.DiscardOldestPolicy();
} else if (rejectedExecutionHandler.equals("DiscardPolicy")) {
handler = new ThreadPoolExecutor.DiscardPolicy();
} else {
handler = new ThreadPoolExecutor.AbortPolicy();
}
executor.setRejectedExecutionHandler(handler);
return executor; return executor;
} }
@ -46,14 +67,11 @@ public class ThreadPoolConfig
* 执行周期性或定时任务 * 执行周期性或定时任务
*/ */
@Bean(name = "scheduledExecutorService") @Bean(name = "scheduledExecutorService")
protected ScheduledExecutorService scheduledExecutorService() protected ScheduledExecutorService scheduledExecutorService() {
{
return new ScheduledThreadPoolExecutor(corePoolSize, return new ScheduledThreadPoolExecutor(corePoolSize,
new BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build()) new BasicThreadFactory.Builder().namingPattern("schedule-pool-%d").daemon(true).build()) {
{
@Override @Override
protected void afterExecute(Runnable r, Throwable t) protected void afterExecute(Runnable r, Throwable t) {
{
super.afterExecute(r, t); super.afterExecute(r, t);
Threads.printException(r, t); Threads.printException(r, t);
} }