From 837f23080b0cb1d2f055229e040b355fab53e3e5 Mon Sep 17 00:00:00 2001 From: "luoqiangzheng@hz-cpp.com" Date: Mon, 14 Mar 2022 15:05:25 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eladmin-common/pom.xml | 2 +- .../me/zhengjie/config/SwaggerConfig.java | 16 ++-- .../me/zhengjie/utils/ValidationUtil.java | 17 ++-- .../java/me/zhengjie/utils/DateUtilsTest.java | 2 +- .../me/zhengjie/utils/EncryptUtilsTest.java | 5 +- .../java/me/zhengjie/utils/FileUtilTest.java | 4 +- .../me/zhengjie/utils/StringUtilsTest.java | 15 ++- eladmin-generator/pom.xml | 2 +- eladmin-system/pom.xml | 4 +- .../me/zhengjie/config/ConfigurerAdapter.java | 2 +- .../service/impl/MonitorServiceImpl.java | 5 +- eladmin-system/src/main/resources/banner.txt | 2 +- .../EladminSystemApplicationTests.java | 5 +- .../test/java/me/zhengjie/LoginCacheTest.java | 92 +++++++++---------- eladmin-tools/pom.xml | 6 +- pom.xml | 54 ++++------- 16 files changed, 108 insertions(+), 125 deletions(-) diff --git a/eladmin-common/pom.xml b/eladmin-common/pom.xml index 2150b4b7..a349edd4 100644 --- a/eladmin-common/pom.xml +++ b/eladmin-common/pom.xml @@ -9,7 +9,7 @@ 4.0.0 - 5.3.4 + 5.7.22 eladmin-common diff --git a/eladmin-common/src/main/java/me/zhengjie/config/SwaggerConfig.java b/eladmin-common/src/main/java/me/zhengjie/config/SwaggerConfig.java index 50343bcb..b42ddde3 100644 --- a/eladmin-common/src/main/java/me/zhengjie/config/SwaggerConfig.java +++ b/eladmin-common/src/main/java/me/zhengjie/config/SwaggerConfig.java @@ -15,8 +15,8 @@ */ package me.zhengjie.config; +import cn.hutool.core.collection.CollUtil; import com.fasterxml.classmate.TypeResolver; -import com.google.common.base.Predicates; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -29,14 +29,18 @@ import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.schema.AlternateTypeRule; import springfox.documentation.schema.AlternateTypeRuleConvention; -import springfox.documentation.service.*; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.ApiKey; +import springfox.documentation.service.AuthorizationScope; +import springfox.documentation.service.SecurityReference; +import springfox.documentation.service.SecurityScheme; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spi.service.contexts.SecurityContext; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; import java.util.ArrayList; import java.util.List; -import static com.google.common.collect.Lists.newArrayList; + import static springfox.documentation.schema.AlternateTypeRules.newRule; /** @@ -62,7 +66,7 @@ public class SwaggerConfig { .pathMapping("/") .apiInfo(apiInfo()) .select() - .paths(Predicates.not(PathSelectors.regex("/error.*"))) + .paths(PathSelectors.regex("^(?!/error).*")) .paths(PathSelectors.any()) .build() //添加登陆认证 @@ -98,7 +102,7 @@ public class SwaggerConfig { private SecurityContext getContextByPath() { return SecurityContext.builder() .securityReferences(defaultAuth()) - .forPaths(PathSelectors.regex("^(?!/auth).*$")) + .operationSelector(o->o.requestMappingPattern().matches("^(?!/auth).*$")) .build(); } @@ -128,7 +132,7 @@ class SwaggerDataConfig { @Override public List rules() { - return newArrayList(newRule(resolver.resolve(Pageable.class), resolver.resolve(Page.class))); + return CollUtil.newArrayList(newRule(resolver.resolve(Pageable.class), resolver.resolve(Page.class))); } }; } diff --git a/eladmin-common/src/main/java/me/zhengjie/utils/ValidationUtil.java b/eladmin-common/src/main/java/me/zhengjie/utils/ValidationUtil.java index 57a4913d..e561762b 100644 --- a/eladmin-common/src/main/java/me/zhengjie/utils/ValidationUtil.java +++ b/eladmin-common/src/main/java/me/zhengjie/utils/ValidationUtil.java @@ -15,16 +15,17 @@ */ package me.zhengjie.utils; +import cn.hutool.core.lang.Validator; import cn.hutool.core.util.ObjectUtil; import me.zhengjie.exception.BadRequestException; -import org.hibernate.validator.internal.constraintvalidators.hv.EmailValidator; /** * 验证工具 + * * @author Zheng Jie * @date 2018-11-23 */ -public class ValidationUtil{ +public class ValidationUtil { /** * 验证空 @@ -36,10 +37,10 @@ public class ValidationUtil{ } } - /** - * 验证是否为邮箱 - */ - public static boolean isEmail(String email) { - return new EmailValidator().isValid(email, null); - } + /** + * 验证是否为邮箱 + */ + public static boolean isEmail(String email) { + return Validator.isEmail(email); + } } diff --git a/eladmin-common/src/test/java/me/zhengjie/utils/DateUtilsTest.java b/eladmin-common/src/test/java/me/zhengjie/utils/DateUtilsTest.java index 4f28ed37..dfe01e09 100644 --- a/eladmin-common/src/test/java/me/zhengjie/utils/DateUtilsTest.java +++ b/eladmin-common/src/test/java/me/zhengjie/utils/DateUtilsTest.java @@ -1,6 +1,6 @@ package me.zhengjie.utils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.time.LocalDateTime; import java.util.Date; diff --git a/eladmin-common/src/test/java/me/zhengjie/utils/EncryptUtilsTest.java b/eladmin-common/src/test/java/me/zhengjie/utils/EncryptUtilsTest.java index f909d9db..3ec73752 100644 --- a/eladmin-common/src/test/java/me/zhengjie/utils/EncryptUtilsTest.java +++ b/eladmin-common/src/test/java/me/zhengjie/utils/EncryptUtilsTest.java @@ -1,8 +1,9 @@ package me.zhengjie.utils; -import org.junit.Test; -import static org.junit.Assert.*; +import org.junit.jupiter.api.Test; + import static me.zhengjie.utils.EncryptUtils.*; +import static org.junit.jupiter.api.Assertions.assertEquals; public class EncryptUtilsTest { diff --git a/eladmin-common/src/test/java/me/zhengjie/utils/FileUtilTest.java b/eladmin-common/src/test/java/me/zhengjie/utils/FileUtilTest.java index f069c158..48e06bd7 100644 --- a/eladmin-common/src/test/java/me/zhengjie/utils/FileUtilTest.java +++ b/eladmin-common/src/test/java/me/zhengjie/utils/FileUtilTest.java @@ -1,10 +1,10 @@ package me.zhengjie.utils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.mock.web.MockMultipartFile; -import static org.junit.Assert.*; import static me.zhengjie.utils.FileUtil.*; +import static org.junit.jupiter.api.Assertions.assertEquals; public class FileUtilTest { diff --git a/eladmin-common/src/test/java/me/zhengjie/utils/StringUtilsTest.java b/eladmin-common/src/test/java/me/zhengjie/utils/StringUtilsTest.java index 12e875a8..ffb2cf88 100644 --- a/eladmin-common/src/test/java/me/zhengjie/utils/StringUtilsTest.java +++ b/eladmin-common/src/test/java/me/zhengjie/utils/StringUtilsTest.java @@ -1,13 +1,18 @@ package me.zhengjie.utils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.mock.web.MockHttpServletRequest; import java.text.SimpleDateFormat; -import java.util.*; +import java.util.Date; -import static me.zhengjie.utils.StringUtils.*; -import static org.junit.Assert.*; +import static me.zhengjie.utils.StringUtils.getIp; +import static me.zhengjie.utils.StringUtils.getWeekDay; +import static me.zhengjie.utils.StringUtils.toCamelCase; +import static me.zhengjie.utils.StringUtils.toCapitalizeCamelCase; +import static me.zhengjie.utils.StringUtils.toUnderScoreCase; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; public class StringUtilsTest { @@ -40,4 +45,4 @@ public class StringUtilsTest { public void testGetIP() { assertEquals("127.0.0.1", getIp(new MockHttpServletRequest())); } -} \ No newline at end of file +} diff --git a/eladmin-generator/pom.xml b/eladmin-generator/pom.xml index 52cdcfbe..96089616 100644 --- a/eladmin-generator/pom.xml +++ b/eladmin-generator/pom.xml @@ -13,7 +13,7 @@ 代码生成模块 - 1.9 + 1.10 diff --git a/eladmin-system/pom.xml b/eladmin-system/pom.xml index 46d81786..fc36c5c5 100644 --- a/eladmin-system/pom.xml +++ b/eladmin-system/pom.xml @@ -13,7 +13,7 @@ 核心模块 - 0.11.1 + 0.11.2 5.8.0 @@ -84,7 +84,7 @@ com.github.oshi oshi-core - 5.7.1 + 6.1.4 diff --git a/eladmin-system/src/main/java/me/zhengjie/config/ConfigurerAdapter.java b/eladmin-system/src/main/java/me/zhengjie/config/ConfigurerAdapter.java index dca5b94b..a0093d68 100644 --- a/eladmin-system/src/main/java/me/zhengjie/config/ConfigurerAdapter.java +++ b/eladmin-system/src/main/java/me/zhengjie/config/ConfigurerAdapter.java @@ -54,7 +54,7 @@ public class ConfigurerAdapter implements WebMvcConfigurer { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = new CorsConfiguration(); config.setAllowCredentials(true); - config.addAllowedOrigin("*"); + config.addAllowedOriginPattern("*"); config.addAllowedHeader("*"); config.addAllowedMethod("*"); source.registerCorsConfiguration("/**", config); diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MonitorServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MonitorServiceImpl.java index 7ff2e91b..6e7e5222 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MonitorServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MonitorServiceImpl.java @@ -15,9 +15,8 @@ */ package me.zhengjie.modules.system.service.impl; -import cn.hutool.core.date.BetweenFormater; +import cn.hutool.core.date.BetweenFormatter.Level; import cn.hutool.core.date.DateUtil; -import me.zhengjie.exception.BadRequestException; import me.zhengjie.modules.system.service.MonitorService; import me.zhengjie.utils.ElAdminConstant; import me.zhengjie.utils.FileUtil; @@ -177,7 +176,7 @@ public class MonitorServiceImpl implements MonitorService { long time = ManagementFactory.getRuntimeMXBean().getStartTime(); Date date = new Date(time); // 计算项目运行时间 - String formatBetween = DateUtil.formatBetween(date, new Date(),BetweenFormater.Level.HOUR); + String formatBetween = DateUtil.formatBetween(date, new Date(), Level.HOUR); // 系统信息 systemInfo.put("os", os.toString()); systemInfo.put("day", formatBetween); diff --git a/eladmin-system/src/main/resources/banner.txt b/eladmin-system/src/main/resources/banner.txt index d0f401a8..cc460ce3 100644 --- a/eladmin-system/src/main/resources/banner.txt +++ b/eladmin-system/src/main/resources/banner.txt @@ -5,4 +5,4 @@ | __| | | (_| | (_| | | | | | | | | | | \___|_| \__,_|\__,_|_| |_| |_|_|_| |_| - :: Spring Boot :: (v2.1.0.RELEASE) \ No newline at end of file + :: Spring Boot :: (v2.6.4) \ No newline at end of file diff --git a/eladmin-system/src/test/java/me/zhengjie/EladminSystemApplicationTests.java b/eladmin-system/src/test/java/me/zhengjie/EladminSystemApplicationTests.java index 45d52120..d3986f0f 100644 --- a/eladmin-system/src/test/java/me/zhengjie/EladminSystemApplicationTests.java +++ b/eladmin-system/src/test/java/me/zhengjie/EladminSystemApplicationTests.java @@ -1,11 +1,8 @@ package me.zhengjie; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class EladminSystemApplicationTests { diff --git a/eladmin-system/src/test/java/me/zhengjie/LoginCacheTest.java b/eladmin-system/src/test/java/me/zhengjie/LoginCacheTest.java index 4cae4a8f..9ebbfaab 100644 --- a/eladmin-system/src/test/java/me/zhengjie/LoginCacheTest.java +++ b/eladmin-system/src/test/java/me/zhengjie/LoginCacheTest.java @@ -1,64 +1,62 @@ package me.zhengjie; import me.zhengjie.modules.security.service.UserDetailsServiceImpl; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class LoginCacheTest { - @Resource(name = "userDetailsService") - private UserDetailsServiceImpl userDetailsService; - ExecutorService executor = Executors.newCachedThreadPool(); + @Resource(name = "userDetailsService") + private UserDetailsServiceImpl userDetailsService; - @Test - public void testCache() throws InterruptedException { - long start1 = System.currentTimeMillis(); - int size = 1000; - CountDownLatch latch = new CountDownLatch(size); - for (int i = 0; i < size; i++) { - executor.submit(() -> userDetailsService.loadUserByUsername("admin")); + ExecutorService executor = Executors.newCachedThreadPool(); + + @Test + public void testCache() throws InterruptedException { + long start1 = System.currentTimeMillis(); + int size = 1000; + CountDownLatch latch = new CountDownLatch(size); + for (int i = 0; i < size; i++) { + executor.submit(() -> userDetailsService.loadUserByUsername("admin")); + latch.countDown(); + } + latch.await(); + + long end1 = System.currentTimeMillis(); + // 关闭缓存 + userDetailsService.setEnableCache(false); + long start2 = System.currentTimeMillis(); + for (int i = 0; i < size; i++) { + userDetailsService.loadUserByUsername("admin"); + } + long end2 = System.currentTimeMillis(); + System.out.print("使用缓存:" + (end1 - start1) + "毫秒\n 不使用缓存:" + (end2 - start2) + "毫秒"); + } + + @Test + public void testCacheManager() throws InterruptedException { + int size = 1000; + CountDownLatch latch = new CountDownLatch(size); + for (int i = 0; i < size; i++) { + int mod = i % 10; + executor.submit( + () -> { + try { + Thread.sleep(mod * 2 + (int) (Math.random() * 10000)); + } catch (InterruptedException e) { + e.printStackTrace(); + } + userDetailsService.loadUserByUsername("admin" + mod); latch.countDown(); - } - latch.await(); - - long end1 = System.currentTimeMillis(); - //关闭缓存 - userDetailsService.setEnableCache(false); - long start2 = System.currentTimeMillis(); - for (int i = 0; i < size; i++) { - userDetailsService.loadUserByUsername("admin"); - } - long end2 = System.currentTimeMillis(); - System.out.print("使用缓存:" + (end1 - start1) + "毫秒\n 不使用缓存:" + (end2 - start2) + "毫秒"); + System.out.println("剩余未完成数量" + latch.getCount()); + }); } - - @Test - public void testCacheManager() throws InterruptedException { - int size = 1000; - CountDownLatch latch = new CountDownLatch(size); - for (int i = 0; i < size; i++) { - int mod = i % 10; - executor.submit(() -> { - try { - Thread.sleep(mod * 2 + (int) (Math.random() * 10000)); - } catch (InterruptedException e) { - e.printStackTrace(); - } - userDetailsService.loadUserByUsername("admin" + mod); - latch.countDown(); - System.out.println("剩余未完成数量" + latch.getCount()); - }); - } - latch.await(); - } - + latch.await(); + } } diff --git a/eladmin-tools/pom.xml b/eladmin-tools/pom.xml index 4bbf9f4c..dbf5e63b 100644 --- a/eladmin-tools/pom.xml +++ b/eladmin-tools/pom.xml @@ -14,8 +14,8 @@ 1.4.7 - [7.2.0, 7.2.99] - 4.9.153.ALL + 7.9.3 + 4.22.57.ALL @@ -47,4 +47,4 @@ ${alipay.version} - \ No newline at end of file + diff --git a/pom.xml b/pom.xml index 0f82d1a1..dbcc3d4b 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ org.springframework.boot spring-boot-starter-parent - 2.2.10.RELEASE + 2.6.4 @@ -34,10 +34,10 @@ 1.8 1.16 2.9.2 - 1.2.70 - 1.1.24 - 2.5.0 - 1.3.1.Final + 1.2.79 + 1.2.8 + 2.11.1 + 1.4.2.Final @@ -80,6 +80,7 @@ + org.apache.commons commons-pool2 @@ -98,37 +99,14 @@ + - io.springfox - springfox-swagger2 - ${swagger.version} - - - io.swagger - swagger-annotations - - - io.swagger - swagger-models - - - - - io.springfox - springfox-swagger-ui - ${swagger.version} - - - io.swagger - swagger-annotations - 1.5.21 - - - io.swagger - swagger-models - 1.5.21 + com.github.xiaoymin + knife4j-spring-boot-starter + 3.0.3 + mysql @@ -144,13 +122,13 @@ + net.dreamlu mica-ip2region - 2.5.6 + 2.6.3 - org.projectlombok @@ -162,12 +140,12 @@ org.apache.poi poi - 3.17 + 5.2.0 org.apache.poi poi-ooxml - 3.17 + 5.2.0 xerces @@ -211,7 +189,7 @@ nl.basjes.parse.useragent yauaa - 5.23 + 6.11 From 68608b28e34ffa73d12df74555e9dc7d63bfc532 Mon Sep 17 00:00:00 2001 From: Aborn Jiang Date: Tue, 31 May 2022 17:57:37 +0800 Subject: [PATCH 2/9] Column use `` for reserved key (#743) * fix weird prefixes keys when use RedisUtils.scan * Column use `` for reserved key ref: https://stackoverflow.com/questions/2224503/how-to-map-an-entity-field-whose-name-is-a-reserved-word-in-jpa --- .../src/main/resources/template/generator/admin/Entity.ftl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eladmin-system/src/main/resources/template/generator/admin/Entity.ftl b/eladmin-system/src/main/resources/template/generator/admin/Entity.ftl index 9d8b1e71..c5cf9c26 100644 --- a/eladmin-system/src/main/resources/template/generator/admin/Entity.ftl +++ b/eladmin-system/src/main/resources/template/generator/admin/Entity.ftl @@ -55,7 +55,7 @@ public class ${className} implements Serializable { @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "${column.columnName}"<#if column.columnKey = 'UNI'>,unique = true<#if column.istNotNull && column.columnKey != 'PRI'>,nullable = false) + @Column(name = "`${column.columnName}`"<#if column.columnKey = 'UNI'>,unique = true<#if column.istNotNull && column.columnKey != 'PRI'>,nullable = false) <#if column.istNotNull && column.columnKey != 'PRI'> <#if column.columnType = 'String'> @NotBlank @@ -82,4 +82,4 @@ public class ${className} implements Serializable { public void copy(${className} source){ BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); } -} \ No newline at end of file +} From 22c3864dee8828b5e0f14655239b32e0a20d787b Mon Sep 17 00:00:00 2001 From: Zheng Jie <201507802@qq.com> Date: Tue, 7 Jun 2022 18:21:52 +0800 Subject: [PATCH 3/9] =?UTF-8?q?[=E6=96=B0=E5=A2=9E=E5=8A=9F=E8=83=BD](luoq?= =?UTF-8?q?iz-master):=20=E8=AE=B0=E5=BD=95=E7=99=BB=E5=BD=95=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/me/zhengjie/service/impl/LogServiceImpl.java | 7 +++++++ .../modules/security/rest/AuthorizationController.java | 2 ++ 2 files changed, 9 insertions(+) diff --git a/eladmin-logging/src/main/java/me/zhengjie/service/impl/LogServiceImpl.java b/eladmin-logging/src/main/java/me/zhengjie/service/impl/LogServiceImpl.java index ecc6efb8..729a7930 100644 --- a/eladmin-logging/src/main/java/me/zhengjie/service/impl/LogServiceImpl.java +++ b/eladmin-logging/src/main/java/me/zhengjie/service/impl/LogServiceImpl.java @@ -17,6 +17,7 @@ package me.zhengjie.service.impl; import cn.hutool.core.lang.Dict; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import lombok.RequiredArgsConstructor; import me.zhengjie.domain.Log; @@ -94,6 +95,12 @@ public class LogServiceImpl implements LogService { log.setMethod(methodName); log.setUsername(username); log.setParams(getParameter(method, joinPoint.getArgs())); + // 记录登录用户,隐藏密码信息 + if(log.getDescription().equals("用户登录")){ + JSONObject obj = JSONUtil.parseObj(log.getParams()); + log.setUsername(obj.get("username").toString()); + log.setParams(JSONUtil.toJsonStr(Dict.create().set("username", log.getUsername()))); + } log.setBrowser(browser); logRepository.save(log); } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/security/rest/AuthorizationController.java b/eladmin-system/src/main/java/me/zhengjie/modules/security/rest/AuthorizationController.java index 634356d5..a157874f 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/security/rest/AuthorizationController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/security/rest/AuthorizationController.java @@ -21,6 +21,7 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import me.zhengjie.annotation.Log; import me.zhengjie.annotation.rest.AnonymousDeleteMapping; import me.zhengjie.annotation.rest.AnonymousGetMapping; import me.zhengjie.annotation.rest.AnonymousPostMapping; @@ -70,6 +71,7 @@ public class AuthorizationController { @Resource private LoginProperties loginProperties; + @Log("用户登录") @ApiOperation("登录授权") @AnonymousPostMapping(value = "/login") public ResponseEntity login(@Validated @RequestBody AuthUserDto authUser, HttpServletRequest request) throws Exception { From 2dc528a103a1601511579e3b1b756a7aaa29665b Mon Sep 17 00:00:00 2001 From: Zheng Jie <201507802@qq.com> Date: Fri, 10 Jun 2022 19:56:28 +0800 Subject: [PATCH 4/9] =?UTF-8?q?[Bug=E4=BF=AE=E5=A4=8D](master):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=AD=98=E5=9C=A8SQL=E6=B3=A8=E5=85=A5=E6=BC=8F?= =?UTF-8?q?=E6=B4=9E=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 由于定时任务未对Bean进行过滤,导致攻击者可以从SpringContextHolder获得控制jdbcTemplate类,并使用getDeclaredMethod调用jdbcTemplate的queryForMap函数,从而执行任意sql命令。 修复后定时任务的 Bean 需要使用 @Service 注解定义。 --- .../java/me/zhengjie/utils/SpringContextHolder.java | 11 +++++++++++ .../modules/quartz/rest/QuartzJobController.java | 13 +++++++++++++ .../me/zhengjie/modules/quartz/task/TestTask.java | 4 ++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/eladmin-common/src/main/java/me/zhengjie/utils/SpringContextHolder.java b/eladmin-common/src/main/java/me/zhengjie/utils/SpringContextHolder.java index d5a50bcf..41ead386 100644 --- a/eladmin-common/src/main/java/me/zhengjie/utils/SpringContextHolder.java +++ b/eladmin-common/src/main/java/me/zhengjie/utils/SpringContextHolder.java @@ -21,7 +21,9 @@ import org.springframework.beans.factory.DisposableBean; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.core.env.Environment; +import org.springframework.stereotype.Service; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -142,4 +144,13 @@ public class SpringContextHolder implements ApplicationContextAware, DisposableB } SpringContextHolder.addCallback = false; } + + /** + * 获取 @Service 的所有 bean 名称 + * @return / + */ + public static List getAllServiceBeanName() { + return new ArrayList<>(Arrays.asList(applicationContext + .getBeanNamesForAnnotation(Service.class))); + } } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/quartz/rest/QuartzJobController.java b/eladmin-system/src/main/java/me/zhengjie/modules/quartz/rest/QuartzJobController.java index 31613572..0ffee652 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/quartz/rest/QuartzJobController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/quartz/rest/QuartzJobController.java @@ -24,6 +24,7 @@ import me.zhengjie.exception.BadRequestException; import me.zhengjie.modules.quartz.domain.QuartzJob; import me.zhengjie.modules.quartz.service.QuartzJobService; import me.zhengjie.modules.quartz.service.dto.JobQueryCriteria; +import me.zhengjie.utils.SpringContextHolder; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -84,6 +85,8 @@ public class QuartzJobController { if (resources.getId() != null) { throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID"); } + // 验证Bean是不是合法的,合法的定时任务 Bean 需要用 @Service 定义 + checkBean(resources.getBeanName()); quartzJobService.create(resources); return new ResponseEntity<>(HttpStatus.CREATED); } @@ -93,6 +96,8 @@ public class QuartzJobController { @PutMapping @PreAuthorize("@el.check('timing:edit')") public ResponseEntity updateQuartzJob(@Validated(QuartzJob.Update.class) @RequestBody QuartzJob resources){ + // 验证Bean是不是合法的,合法的定时任务 Bean 需要用 @Service 定义 + checkBean(resources.getBeanName()); quartzJobService.update(resources); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } @@ -123,4 +128,12 @@ public class QuartzJobController { quartzJobService.delete(ids); return new ResponseEntity<>(HttpStatus.OK); } + + private void checkBean(String beanName){ + // 避免调用攻击者可以从SpringContextHolder获得控制jdbcTemplate类 + // 并使用getDeclaredMethod调用jdbcTemplate的queryForMap函数,执行任意sql命令。 + if(!SpringContextHolder.getAllServiceBeanName().contains(beanName)){ + throw new BadRequestException("非法的 Bean,请重新输入!"); + } + } } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/TestTask.java b/eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/TestTask.java index da1c8ff4..4cf34342 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/TestTask.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/TestTask.java @@ -16,7 +16,7 @@ package me.zhengjie.modules.quartz.task; import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; /** * 测试用 @@ -24,7 +24,7 @@ import org.springframework.stereotype.Component; * @date 2019-01-08 */ @Slf4j -@Component +@Service public class TestTask { public void run(){ From b7b721b13b9d7be7134e2d66706d30ffdf7acd87 Mon Sep 17 00:00:00 2001 From: Zheng Jie <201507802@qq.com> Date: Sun, 12 Jun 2022 15:55:15 +0800 Subject: [PATCH 5/9] =?UTF-8?q?[=E4=BB=A3=E7=A0=81=E5=AE=8C=E5=96=84](mast?= =?UTF-8?q?er):=20=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/system/repository/MenuRepository.java | 4 ++-- .../modules/system/service/impl/MenuServiceImpl.java | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/system/repository/MenuRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/system/repository/MenuRepository.java index 0907606f..75fd7ff5 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/system/repository/MenuRepository.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/system/repository/MenuRepository.java @@ -49,13 +49,13 @@ public interface MenuRepository extends JpaRepository, JpaSpecificat * @param pid / * @return / */ - List findByPid(long pid); + List findByPidOrderByMenuSort(long pid); /** * 查询顶级菜单 * @return / */ - List findByPidIsNull(); + List findByPidIsNullOrderByMenuSort(); /** * 根据角色ID与菜单类型查询菜单 diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MenuServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MenuServiceImpl.java index 229186bd..c1bc4d1f 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MenuServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MenuServiceImpl.java @@ -189,7 +189,7 @@ public class MenuServiceImpl implements MenuService { public Set getChildMenus(List menuList, Set menuSet) { for (Menu menu : menuList) { menuSet.add(menu); - List menus = menuRepository.findByPid(menu.getId()); + List menus = menuRepository.findByPidOrderByMenuSort(menu.getId()); if(menus!=null && menus.size()!=0){ getChildMenus(menus, menuSet); } @@ -213,9 +213,9 @@ public class MenuServiceImpl implements MenuService { public List getMenus(Long pid) { List menus; if(pid != null && !pid.equals(0L)){ - menus = menuRepository.findByPid(pid); + menus = menuRepository.findByPidOrderByMenuSort(pid); } else { - menus = menuRepository.findByPidIsNull(); + menus = menuRepository.findByPidIsNullOrderByMenuSort(); } return menuMapper.toDto(menus); } @@ -223,10 +223,10 @@ public class MenuServiceImpl implements MenuService { @Override public List getSuperior(MenuDto menuDto, List menus) { if(menuDto.getPid() == null){ - menus.addAll(menuRepository.findByPidIsNull()); + menus.addAll(menuRepository.findByPidIsNullOrderByMenuSort()); return menuMapper.toDto(menus); } - menus.addAll(menuRepository.findByPid(menuDto.getPid())); + menus.addAll(menuRepository.findByPidOrderByMenuSort(menuDto.getPid())); return getSuperior(findById(menuDto.getPid()), menus); } From 7cef6f8bf289f89e4e9dd2e52046085266c05727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E9=87=91=E8=80=80?= <94180588@qq.com> Date: Tue, 14 Jun 2022 07:24:56 +0000 Subject: [PATCH 6/9] =?UTF-8?q?!30=20=E8=A7=A3=E5=86=B3=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=89=8D=E6=AE=B5=E4=BB=A3=E7=A0=81=E5=AD=97=E5=85=B8=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E9=87=8D=E5=A4=8Dbug=20*=20=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E7=94=9F=E4=BA=A7=E5=89=8D=E6=AE=B5=E4=BB=A3=E7=A0=81=E5=AD=97?= =?UTF-8?q?=E5=85=B8=E6=95=B0=E6=8D=AE=E9=87=8D=E5=A4=8Dbug=EF=BC=9A?= =?UTF-8?q?=E4=BD=86=E4=B8=80=E4=B8=AA=E9=A1=B5=E9=9D=A2=E4=B8=AD=E5=A4=9A?= =?UTF-8?q?=E4=B8=AA=E9=A1=B9=E7=9B=AE=E7=AE=A1=E7=90=86=E5=90=8C=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E5=AD=97=E5=85=B8=E6=97=B6=EF=BC=8C=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=87=8D=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/me/zhengjie/utils/GenUtil.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/eladmin-generator/src/main/java/me/zhengjie/utils/GenUtil.java b/eladmin-generator/src/main/java/me/zhengjie/utils/GenUtil.java index b1cb249e..d197a3ca 100644 --- a/eladmin-generator/src/main/java/me/zhengjie/utils/GenUtil.java +++ b/eladmin-generator/src/main/java/me/zhengjie/utils/GenUtil.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2019-2020 Zheng Jie * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -276,7 +276,8 @@ public class GenUtil { // 主键存在字典 if (StringUtils.isNotBlank(column.getDictName())) { genMap.put("hasDict", true); - dicts.add(column.getDictName()); + if(!dicts.contains(column.getDictName())) + dicts.add(column.getDictName()); } // 存储字段类型 From 20f2c6362ee12d4a44356922aff8945f6d8c7c32 Mon Sep 17 00:00:00 2001 From: Zheng Jie <201507802@qq.com> Date: Tue, 14 Jun 2022 16:32:03 +0800 Subject: [PATCH 7/9] =?UTF-8?q?[=E4=BB=A3=E7=A0=81=E5=AE=8C=E5=96=84](mast?= =?UTF-8?q?er):=20=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/service/impl/MonitorServiceImpl.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MonitorServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MonitorServiceImpl.java index 6e7e5222..fd69a222 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MonitorServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MonitorServiceImpl.java @@ -148,9 +148,15 @@ public class MonitorServiceImpl implements MonitorService { cpuInfo.put("logic", processor.getLogicalProcessorCount() + "个逻辑CPU"); // CPU信息 long[] prevTicks = processor.getSystemCpuLoadTicks(); - // 等待1秒... - Util.sleep(1000); + // 默认等待300毫秒... + long time = 300; + Util.sleep(time); long[] ticks = processor.getSystemCpuLoadTicks(); + while (Arrays.toString(prevTicks).equals(Arrays.toString(ticks)) && time < 1000){ + time += 25; + Util.sleep(25); + ticks = processor.getSystemCpuLoadTicks(); + } long user = ticks[CentralProcessor.TickType.USER.getIndex()] - prevTicks[CentralProcessor.TickType.USER.getIndex()]; long nice = ticks[CentralProcessor.TickType.NICE.getIndex()] - prevTicks[CentralProcessor.TickType.NICE.getIndex()]; long sys = ticks[CentralProcessor.TickType.SYSTEM.getIndex()] - prevTicks[CentralProcessor.TickType.SYSTEM.getIndex()]; From 64a3ff7b26b15470f5473d04dcd0c7bbb23b6e39 Mon Sep 17 00:00:00 2001 From: xiaoyong <56395147+xiaoyonghaoe@users.noreply.github.com> Date: Sun, 3 Jul 2022 22:25:49 +0800 Subject: [PATCH 8/9] Issues635 (#751) * issues/635 * issues/635 Co-authored-by: asdc --- .../zhengjie/modules/system/service/impl/DataServiceImpl.java | 2 +- .../zhengjie/modules/system/service/impl/UserServiceImpl.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DataServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DataServiceImpl.java index 33a81480..2933db9c 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DataServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DataServiceImpl.java @@ -43,7 +43,7 @@ public class DataServiceImpl implements DataService { private final DeptService deptService; /** - * 用户角色改变时需清理缓存 + * 用户角色和用户部门改变时需清理缓存 * @param user / * @return / */ diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java index 6342d130..867509d3 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java @@ -119,6 +119,10 @@ public class UserServiceImpl implements UserService { redisUtils.del(CacheKey.MENU_USER + resources.getId()); redisUtils.del(CacheKey.ROLE_AUTH + resources.getId()); } + // 修改部门会影响 数据权限 + if (!Objects.equals(resources.getDept(),user.getDept())) { + redisUtils.del(CacheKey.DATA_USER + resources.getId()); + } // 如果用户被禁用,则清除用户登录信息 if(!resources.getEnabled()){ onlineUserService.kickOutForUsername(resources.getUsername()); From 255a3254ce9eaefc4ac67816ebfc020d5c93bff0 Mon Sep 17 00:00:00 2001 From: Zheng Jie <201507802@qq.com> Date: Mon, 4 Jul 2022 11:44:54 +0800 Subject: [PATCH 9/9] =?UTF-8?q?[=E4=BB=A3=E7=A0=81=E5=AE=8C=E5=96=84](mast?= =?UTF-8?q?er):=20=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96=20close=20https://g?= =?UTF-8?q?ithub.com/elunez/eladmin/issues/752?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/me/zhengjie/utils/GenUtil.java | 2 +- .../config/thread/AsyncTaskExecutePool.java | 4 ++-- .../zhengjie/config/thread/TheadFactoryName.java | 15 ++++++++------- .../config/thread/ThreadPoolExecutorUtil.java | 11 +++++++++-- .../modules/quartz/utils/ExecutionJob.java | 9 ++++----- 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/eladmin-generator/src/main/java/me/zhengjie/utils/GenUtil.java b/eladmin-generator/src/main/java/me/zhengjie/utils/GenUtil.java index d197a3ca..b62efa2d 100644 --- a/eladmin-generator/src/main/java/me/zhengjie/utils/GenUtil.java +++ b/eladmin-generator/src/main/java/me/zhengjie/utils/GenUtil.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2019-2020 Zheng Jie * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/eladmin-system/src/main/java/me/zhengjie/config/thread/AsyncTaskExecutePool.java b/eladmin-system/src/main/java/me/zhengjie/config/thread/AsyncTaskExecutePool.java index 133cf55f..dc9d1bc3 100644 --- a/eladmin-system/src/main/java/me/zhengjie/config/thread/AsyncTaskExecutePool.java +++ b/eladmin-system/src/main/java/me/zhengjie/config/thread/AsyncTaskExecutePool.java @@ -43,8 +43,8 @@ public class AsyncTaskExecutePool implements AsyncConfigurer { executor.setQueueCapacity(AsyncTaskProperties.queueCapacity); //活跃时间 executor.setKeepAliveSeconds(AsyncTaskProperties.keepAliveSeconds); - //线程名字前缀 - executor.setThreadNamePrefix("el-async-"); + //线程工厂 + executor.setThreadFactory(new TheadFactoryName("el-async")); // setRejectedExecutionHandler:当pool已经达到max size的时候,如何处理新任务 // CallerRunsPolicy:不在新线程中执行任务,而是由调用者所在的线程来执行 executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); diff --git a/eladmin-system/src/main/java/me/zhengjie/config/thread/TheadFactoryName.java b/eladmin-system/src/main/java/me/zhengjie/config/thread/TheadFactoryName.java index 4cc8ae91..be227fd5 100644 --- a/eladmin-system/src/main/java/me/zhengjie/config/thread/TheadFactoryName.java +++ b/eladmin-system/src/main/java/me/zhengjie/config/thread/TheadFactoryName.java @@ -15,8 +15,8 @@ */ package me.zhengjie.config.thread; +import me.zhengjie.utils.StringUtils; import org.springframework.stereotype.Component; - import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicInteger; @@ -33,24 +33,25 @@ public class TheadFactoryName implements ThreadFactory { private final AtomicInteger threadNumber = new AtomicInteger(1); private final String namePrefix; + private final static String DEF_NAME = "el-pool-"; + public TheadFactoryName() { - this("el-pool"); + this(DEF_NAME); } - private TheadFactoryName(String name){ + public TheadFactoryName(String name){ SecurityManager s = System.getSecurityManager(); group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup(); //此时namePrefix就是 name + 第几个用这个工厂创建线程池的 - this.namePrefix = name + - POOL_NUMBER.getAndIncrement(); + this.namePrefix = (StringUtils.isNotBlank(name) ? name : DEF_NAME) + "-" + POOL_NUMBER.getAndIncrement(); } @Override public Thread newThread(Runnable r) { - //此时线程的名字 就是 namePrefix + -thread- + 这个线程池中第几个执行的线程 + //此时线程的名字 就是 namePrefix + -exec- + 这个线程池中第几个执行的线程 Thread t = new Thread(group, r, - namePrefix + "-thread-"+threadNumber.getAndIncrement(), + namePrefix + "-exec-"+threadNumber.getAndIncrement(), 0); if (t.isDaemon()) { t.setDaemon(false); diff --git a/eladmin-system/src/main/java/me/zhengjie/config/thread/ThreadPoolExecutorUtil.java b/eladmin-system/src/main/java/me/zhengjie/config/thread/ThreadPoolExecutorUtil.java index 8e04aa2b..dc93fe51 100644 --- a/eladmin-system/src/main/java/me/zhengjie/config/thread/ThreadPoolExecutorUtil.java +++ b/eladmin-system/src/main/java/me/zhengjie/config/thread/ThreadPoolExecutorUtil.java @@ -16,6 +16,7 @@ package me.zhengjie.config.thread; import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.ExecutorService; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -26,14 +27,20 @@ import java.util.concurrent.TimeUnit; */ public class ThreadPoolExecutorUtil { - public static ThreadPoolExecutor getPoll(){ + public static ExecutorService getPoll(){ + return getPoll(null); + } + + public static ExecutorService getPoll(String threadName){ return new ThreadPoolExecutor( AsyncTaskProperties.corePoolSize, AsyncTaskProperties.maxPoolSize, AsyncTaskProperties.keepAliveSeconds, TimeUnit.SECONDS, new ArrayBlockingQueue<>(AsyncTaskProperties.queueCapacity), - new TheadFactoryName() + new TheadFactoryName(threadName), + // 队列与线程池中线程都满了时使用调用者所在的线程来执行 + new ThreadPoolExecutor.CallerRunsPolicy() ); } } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/ExecutionJob.java b/eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/ExecutionJob.java index 0b352079..5d298ced 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/ExecutionJob.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/ExecutionJob.java @@ -19,6 +19,7 @@ import cn.hutool.extra.template.Template; import cn.hutool.extra.template.TemplateConfig; import cn.hutool.extra.template.TemplateEngine; import cn.hutool.extra.template.TemplateUtil; +import me.zhengjie.config.thread.ThreadPoolExecutorUtil; import me.zhengjie.domain.vo.EmailVo; import me.zhengjie.modules.quartz.domain.QuartzJob; import me.zhengjie.modules.quartz.domain.QuartzLog; @@ -32,7 +33,6 @@ import me.zhengjie.utils.ThrowableUtil; import org.quartz.JobExecutionContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.quartz.QuartzJobBean; import java.util.*; import java.util.concurrent.*; @@ -42,15 +42,15 @@ import java.util.concurrent.*; * @author / * @date 2019-01-07 */ -@Async public class ExecutionJob extends QuartzJobBean { private final Logger logger = LoggerFactory.getLogger(this.getClass()); + // 此处仅供参考,可根据任务执行情况自定义线程池参数 + private final static ExecutorService executor = ThreadPoolExecutorUtil.getPoll("el-quartz-job"); + @Override public void executeInternal(JobExecutionContext context) { - // 创建单个线程 - ExecutorService executor = Executors.newSingleThreadExecutor(); // 获取任务 QuartzJob quartzJob = (QuartzJob) context.getMergedJobDataMap().get(QuartzJob.JOB_KEY); // 获取spring bean @@ -112,7 +112,6 @@ public class ExecutionJob extends QuartzJobBean { } } finally { quartzLogRepository.save(log); - executor.shutdown(); } }