diff --git a/eladmin/eladmin-common/src/main/java/me/zhengjie/config/AsyncExecutor.java b/eladmin/eladmin-common/src/main/java/me/zhengjie/config/AsyncExecutor.java index e9b33a5..0cfe938 100644 --- a/eladmin/eladmin-common/src/main/java/me/zhengjie/config/AsyncExecutor.java +++ b/eladmin/eladmin-common/src/main/java/me/zhengjie/config/AsyncExecutor.java @@ -1,9 +1,26 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package me.zhengjie.config; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; +import org.springframework.scheduling.annotation.AsyncConfigurer; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; @@ -13,8 +30,9 @@ import java.util.concurrent.atomic.AtomicInteger; * @description * @date 2023-06-08 **/ +@EnableAsync @Configuration -public class AsyncExecutor { +public class AsyncExecutor implements AsyncConfigurer { public static int corePoolSize; @@ -48,9 +66,8 @@ public class AsyncExecutor { * 自定义线程池,用法 @Async * @return Executor */ - @Bean - @Primary - public Executor elAsync() { + @Override + public Executor getAsyncExecutor() { // 自定义工厂 ThreadFactory factory = r -> new Thread(r, "el-async-" + new AtomicInteger(1).getAndIncrement()); // 自定义线程池 @@ -60,16 +77,19 @@ public class AsyncExecutor { } /** - * 自定义线程池,用法 @Async("otherAsync") - * @return Executor + * 自定义线程池,用法,注入到类中使用 + * private ThreadPoolTaskExecutor taskExecutor; + * @return ThreadPoolTaskExecutor */ - @Bean - public Executor otherAsync() { - // 自定义工厂 - ThreadFactory factory = r -> new Thread(r, "tpl-other-" + new AtomicInteger(1).getAndIncrement()); - // 自定义线程池 - return new ThreadPoolExecutor(2, 4, keepAliveSeconds, - TimeUnit.SECONDS, new ArrayBlockingQueue<>(20), factory, - new ThreadPoolExecutor.CallerRunsPolicy()); + @Bean("taskAsync") + public ThreadPoolTaskExecutor taskAsync() { + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + executor.setCorePoolSize(2); + executor.setMaxPoolSize(4); + executor.setQueueCapacity(20); + executor.setKeepAliveSeconds(60); + executor.setThreadNamePrefix("el-task-"); + executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); + return executor; } } diff --git a/eladmin/eladmin-common/src/main/java/me/zhengjie/config/RedisConfiguration.java b/eladmin/eladmin-common/src/main/java/me/zhengjie/config/RedisConfiguration.java index 0c8e1c0..8f2b149 100644 --- a/eladmin/eladmin-common/src/main/java/me/zhengjie/config/RedisConfiguration.java +++ b/eladmin/eladmin-common/src/main/java/me/zhengjie/config/RedisConfiguration.java @@ -77,6 +77,8 @@ public class RedisConfiguration { ParserConfig.getGlobalInstance().addAccept("me.zhengjie.modules.system.domain"); // 模块内的 Dto ParserConfig.getGlobalInstance().addAccept("me.zhengjie.modules.security.service.dto"); + // 分页返回数据 + ParserConfig.getGlobalInstance().addAccept("me.zhengjie.utils.PageResult"); // key的序列化采用StringRedisSerializer template.setKeySerializer(new StringRedisSerializer()); template.setHashKeySerializer(new StringRedisSerializer()); diff --git a/eladmin/eladmin-generator/src/main/java/me/zhengjie/utils/ColUtil.java b/eladmin/eladmin-generator/src/main/java/me/zhengjie/utils/ColUtil.java index b5fcd6b..f65d06b 100644 --- a/eladmin/eladmin-generator/src/main/java/me/zhengjie/utils/ColUtil.java +++ b/eladmin/eladmin-generator/src/main/java/me/zhengjie/utils/ColUtil.java @@ -45,7 +45,7 @@ public class ColUtil { */ public static PropertiesConfiguration getConfig() { try { - return new PropertiesConfiguration("generator.properties"); + return new PropertiesConfiguration("gen.properties"); } catch (ConfigurationException e) { log.error(e.getMessage(), e); } diff --git a/eladmin/eladmin-logging/src/main/java/me/zhengjie/service/SysLogService.java b/eladmin/eladmin-logging/src/main/java/me/zhengjie/service/SysLogService.java index af39b29..b9b87b4 100644 --- a/eladmin/eladmin-logging/src/main/java/me/zhengjie/service/SysLogService.java +++ b/eladmin/eladmin-logging/src/main/java/me/zhengjie/service/SysLogService.java @@ -21,11 +21,9 @@ import me.zhengjie.domain.SysLog; import me.zhengjie.domain.vo.SysLogQueryCriteria; import me.zhengjie.utils.PageResult; import org.aspectj.lang.ProceedingJoinPoint; -import org.springframework.scheduling.annotation.Async; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.List; -import java.util.Map; /** * @author Zheng Jie @@ -65,7 +63,6 @@ public interface SysLogService extends IService{ * @param joinPoint / * @param sysLog 日志实体 */ - @Async void save(String username, String browser, String ip, ProceedingJoinPoint joinPoint, SysLog sysLog); /** diff --git a/eladmin/eladmin-logging/src/main/java/me/zhengjie/service/impl/SysLogServiceImpl.java b/eladmin/eladmin-logging/src/main/java/me/zhengjie/service/impl/SysLogServiceImpl.java index 991715c..9d88928 100644 --- a/eladmin/eladmin-logging/src/main/java/me/zhengjie/service/impl/SysLogServiceImpl.java +++ b/eladmin/eladmin-logging/src/main/java/me/zhengjie/service/impl/SysLogServiceImpl.java @@ -28,6 +28,7 @@ import me.zhengjie.domain.vo.SysLogQueryCriteria; import me.zhengjie.utils.*; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.reflect.MethodSignature; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.RequestBody; @@ -63,6 +64,7 @@ public class SysLogServiceImpl extends ServiceImpl impleme return PageUtil.toPage(sysLogMapper.queryAllByUser(criteria, page)); } + @Async @Override @Transactional(rollbackFor = Exception.class) public void save(String username, String browser, String ip, ProceedingJoinPoint joinPoint, SysLog sysLog) { diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/AppRun.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/AppRun.java index 83eb72a..5c1f72b 100644 --- a/eladmin/eladmin-system/src/main/java/me/zhengjie/AppRun.java +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/AppRun.java @@ -23,7 +23,6 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.ApplicationPidFileWriter; import org.springframework.context.annotation.Bean; -import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.web.bind.annotation.RestController; @@ -32,7 +31,6 @@ import org.springframework.web.bind.annotation.RestController; * @date 2018/11/15 9:20:19 */ @Slf4j -@EnableAsync @RestController @Api(hidden = true) @SpringBootApplication diff --git a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/impl/QuartzJobServiceImpl.java b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/impl/QuartzJobServiceImpl.java index dd2696d..0eb278e 100644 --- a/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/impl/QuartzJobServiceImpl.java +++ b/eladmin/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/impl/QuartzJobServiceImpl.java @@ -30,7 +30,6 @@ import me.zhengjie.modules.quartz.domain.vo.QuartzJobQueryCriteria; import me.zhengjie.modules.quartz.utils.QuartzManage; import me.zhengjie.utils.*; import org.quartz.CronExpression; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.servlet.http.HttpServletResponse; @@ -124,7 +123,6 @@ public class QuartzJobServiceImpl extends ServiceImpl + + + + \ No newline at end of file diff --git a/eladmin/pom.xml b/eladmin/pom.xml index 5a91c6f..9a0bd26 100644 --- a/eladmin/pom.xml +++ b/eladmin/pom.xml @@ -43,6 +43,18 @@ org.springframework.boot spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + + + org.springframework.boot + spring-boot-starter-undertow