diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/constant/SystemConst.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/constant/SystemConst.java index 4aec0516..dfe5dc18 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/constant/SystemConst.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/constant/SystemConst.java @@ -46,4 +46,6 @@ public interface SystemConst { String SYMBOL_AT = "@"; String PROPERTY_OS_NAME = "os.name"; String OS_NAME_WINDOWS = "Windows"; + String CURRENT_APP_NAME = "cutejava"; + String CURRENT_APP_TITLE = "CuteJava"; } diff --git a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/server/core/KitFileLocalUploadHelper.java b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/server/core/KitFileLocalUploadHelper.java index 720ffa44..e76f110c 100644 --- a/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/server/core/KitFileLocalUploadHelper.java +++ b/cutejava-springboot3/cutejava-framework/src/main/java/cn/odboy/framework/server/core/KitFileLocalUploadHelper.java @@ -18,7 +18,6 @@ package cn.odboy.framework.server.core; import cn.hutool.core.util.StrUtil; import cn.odboy.constant.SystemConst; import cn.odboy.util.KitSystemUtil; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; /** @@ -36,26 +35,24 @@ public class KitFileLocalUploadHelper { private static final String PATH_WINDOWS = "C:\\${appName}\\file\\"; private static final String PATH_MAC = "/Users${username}/${appName}/file/"; private static final String PATH_LINUX = "/home/${appName}/file/"; - @Value("${spring.application.name}") - private String appName; public String getPath() { String os = System.getProperty("os.name"); if (os == null) { // 默认使用 Linux 路径作为兜底方案 - return PATH_LINUX.replace("${appName}", appName); + return PATH_LINUX.replace("${appName}", SystemConst.CURRENT_APP_NAME); } String lowerOs = os.toLowerCase(); if (lowerOs.startsWith(SystemConst.WIN)) { - return PATH_WINDOWS.replace("${appName}", appName); + return PATH_WINDOWS.replace("${appName}", SystemConst.CURRENT_APP_NAME); } else if (lowerOs.startsWith(SystemConst.MAC)) { String currentUserName = KitSystemUtil.getCurrentUserName(); if (StrUtil.isBlank(currentUserName)) { - return PATH_MAC.replace("${appName}", appName).replace("${username}", ""); + return PATH_MAC.replace("${appName}", SystemConst.CURRENT_APP_NAME).replace("${username}", ""); } - return PATH_MAC.replace("${appName}", appName).replace("${username}", currentUserName); + return PATH_MAC.replace("${appName}", SystemConst.CURRENT_APP_NAME).replace("${username}", currentUserName); } - return PATH_LINUX.replace("${appName}", appName); + return PATH_LINUX.replace("${appName}", SystemConst.CURRENT_APP_NAME); } public int getAvatarMaxSize() { diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/storage/local/MultipartConfig.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/storage/local/MultipartConfig.java index 7eaffd14..63e0c30f 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/storage/local/MultipartConfig.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/framework/storage/local/MultipartConfig.java @@ -15,13 +15,13 @@ */ package cn.odboy.system.framework.storage.local; +import cn.odboy.constant.SystemConst; import cn.odboy.framework.exception.BadRequestException; import cn.odboy.framework.properties.AppProperties; -import java.io.File; import jakarta.servlet.MultipartConfigElement; +import java.io.File; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.web.servlet.MultipartConfigFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -31,8 +31,6 @@ import org.springframework.util.unit.DataSize; @Configuration public class MultipartConfig { - @Value("${spring.application.name}") - private String name; @Autowired private AppProperties properties; @@ -44,7 +42,7 @@ public class MultipartConfig { MultipartConfigFactory factory = new MultipartConfigFactory(); factory.setMaxFileSize(DataSize.ofMegabytes(properties.getOss().getMaxSize())); factory.setMaxRequestSize(DataSize.ofMegabytes(properties.getOss().getMaxSize())); - String location = System.getProperty("user.home") + "/" + name + "/tmp"; + String location = System.getProperty("user.home") + "/" + SystemConst.CURRENT_APP_NAME + "/tmp"; File tmpFile = new File(location); if (!tmpFile.exists()) { if (!tmpFile.mkdirs()) { diff --git a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemEmailService.java b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemEmailService.java index 00e9a965..6bb644f0 100644 --- a/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemEmailService.java +++ b/cutejava-springboot3/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemEmailService.java @@ -19,6 +19,7 @@ import cn.hutool.core.lang.Dict; import cn.hutool.core.util.RandomUtil; import cn.hutool.extra.mail.Mail; import cn.hutool.extra.mail.MailAccount; +import cn.odboy.constant.SystemConst; import cn.odboy.framework.exception.BadRequestException; import cn.odboy.framework.properties.AppProperties; import cn.odboy.framework.redis.KitRedisHelper; @@ -32,7 +33,6 @@ import cn.odboy.util.KitResourceTemplateUtil; import java.util.Collections; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -46,8 +46,6 @@ public class SystemEmailService { private KitRedisHelper redisHelper; @Autowired private AppProperties properties; - @Value("${spring.application.title}") - private String applicationTitle; /** * 更新邮件配置 @@ -146,7 +144,7 @@ public class SystemEmailService { KitResourceTemplateUtil.render(null, biEnum.getTemplateName(), Dict.create().set("code", oldCode)); } SystemSendEmailArgs sendEmailRequest = - new SystemSendEmailArgs(Collections.singletonList(email), applicationTitle, content); + new SystemSendEmailArgs(Collections.singletonList(email), SystemConst.CURRENT_APP_TITLE, content); sendEmail(sendEmailRequest); } diff --git a/cutejava-springboot3/cutejava-starter/src/main/resources/application-quartz.yml b/cutejava-springboot3/cutejava-starter/src/main/resources/application-quartz.yml index 35ba2188..dc34ad0e 100644 --- a/cutejava-springboot3/cutejava-starter/src/main/resources/application-quartz.yml +++ b/cutejava-springboot3/cutejava-starter/src/main/resources/application-quartz.yml @@ -9,7 +9,7 @@ spring: quartz: scheduler: # 必需,指定调度器实例的名称 - instanceName: ${spring.application.name} + instanceName: cutejava # 必需,指定调度器实例的 ID instanceId: auto threadPool: diff --git a/cutejava/cutejava-framework/src/main/java/cn/odboy/constant/SystemConst.java b/cutejava/cutejava-framework/src/main/java/cn/odboy/constant/SystemConst.java index 286b953b..b9a25bf6 100644 --- a/cutejava/cutejava-framework/src/main/java/cn/odboy/constant/SystemConst.java +++ b/cutejava/cutejava-framework/src/main/java/cn/odboy/constant/SystemConst.java @@ -46,4 +46,6 @@ public interface SystemConst { String SYMBOL_AT = "@"; String PROPERTY_OS_NAME = "os.name"; String OS_NAME_WINDOWS = "Windows"; + String CURRENT_APP_NAME = "cutejava"; + String CURRENT_APP_TITLE = "CuteJava"; } diff --git a/cutejava/cutejava-framework/src/main/java/cn/odboy/framework/server/core/KitFileLocalUploadHelper.java b/cutejava/cutejava-framework/src/main/java/cn/odboy/framework/server/core/KitFileLocalUploadHelper.java index d9b20580..286cf46c 100644 --- a/cutejava/cutejava-framework/src/main/java/cn/odboy/framework/server/core/KitFileLocalUploadHelper.java +++ b/cutejava/cutejava-framework/src/main/java/cn/odboy/framework/server/core/KitFileLocalUploadHelper.java @@ -18,7 +18,6 @@ package cn.odboy.framework.server.core; import cn.hutool.core.util.StrUtil; import cn.odboy.constant.SystemConst; import cn.odboy.util.KitSystemUtil; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; /** @@ -36,26 +35,24 @@ public class KitFileLocalUploadHelper { private static final String PATH_WINDOWS = "C:\\${appName}\\file\\"; private static final String PATH_MAC = "/Users${username}/${appName}/file/"; private static final String PATH_LINUX = "/home/${appName}/file/"; - @Value("${spring.application.name}") - private String appName; public String getPath() { String os = System.getProperty("os.name"); if (os == null) { // 默认使用 Linux 路径作为兜底方案 - return PATH_LINUX.replace("${appName}", appName); + return PATH_LINUX.replace("${appName}", SystemConst.CURRENT_APP_NAME); } String lowerOs = os.toLowerCase(); if (lowerOs.startsWith(SystemConst.WIN)) { - return PATH_WINDOWS.replace("${appName}", appName); + return PATH_WINDOWS.replace("${appName}", SystemConst.CURRENT_APP_NAME); } else if (lowerOs.startsWith(SystemConst.MAC)) { String currentUserName = KitSystemUtil.getCurrentUserName(); if (StrUtil.isBlank(currentUserName)) { - return PATH_MAC.replace("${appName}", appName).replace("${username}", ""); + return PATH_MAC.replace("${appName}", SystemConst.CURRENT_APP_NAME).replace("${username}", ""); } - return PATH_MAC.replace("${appName}", appName).replace("${username}", "/" + currentUserName); + return PATH_MAC.replace("${appName}", SystemConst.CURRENT_APP_NAME).replace("${username}", "/" + currentUserName); } - return PATH_LINUX.replace("${appName}", appName); + return PATH_LINUX.replace("${appName}", SystemConst.CURRENT_APP_NAME); } public int getAvatarMaxSize() { diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/bizlock/BizLockAspect.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/bizlock/BizLockAspect.java index 9805d137..4d0e1e3b 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/bizlock/BizLockAspect.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/bizlock/BizLockAspect.java @@ -43,8 +43,8 @@ public class BizLockAspect { public Object around(ProceedingJoinPoint joinPoint, BizLock bizLock) throws Throwable { // 解析SpEL表达式生成最终的lockKey String lockKey = parseLockKey(joinPoint, bizLock); - Boolean success = redisHelper.setIfAbsent(lockKey, lockKey, bizLock.leaseTime(), bizLock.timeUnit()); - if (success == null || !success) { + boolean success = redisHelper.setIfAbsent(lockKey, lockKey, bizLock.leaseTime(), bizLock.timeUnit()); + if (!success) { throw new BadRequestException(bizLock.errorMessage()); } try { diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/storage/local/MultipartConfig.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/storage/local/MultipartConfig.java index 74156f46..a4ae4a2b 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/storage/local/MultipartConfig.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/framework/storage/local/MultipartConfig.java @@ -15,6 +15,7 @@ */ package cn.odboy.system.framework.storage.local; +import cn.odboy.constant.SystemConst; import cn.odboy.framework.exception.BadRequestException; import cn.odboy.framework.properties.AppProperties; import java.io.File; @@ -30,9 +31,6 @@ import org.springframework.util.unit.DataSize; @Slf4j @Configuration public class MultipartConfig { - - @Value("${spring.application.name}") - private String name; @Autowired private AppProperties properties; @@ -44,7 +42,7 @@ public class MultipartConfig { MultipartConfigFactory factory = new MultipartConfigFactory(); factory.setMaxFileSize(DataSize.ofMegabytes(properties.getOss().getMaxSize())); factory.setMaxRequestSize(DataSize.ofMegabytes(properties.getOss().getMaxSize())); - String location = System.getProperty("user.home") + "/" + name + "/tmp"; + String location = System.getProperty("user.home") + "/" + SystemConst.CURRENT_APP_NAME + "/tmp"; File tmpFile = new File(location); if (!tmpFile.exists()) { if (!tmpFile.mkdirs()) { diff --git a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemEmailService.java b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemEmailService.java index a795bc10..2256d86f 100644 --- a/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemEmailService.java +++ b/cutejava/cutejava-module-system/src/main/java/cn/odboy/system/service/SystemEmailService.java @@ -19,6 +19,7 @@ import cn.hutool.core.lang.Dict; import cn.hutool.core.util.RandomUtil; import cn.hutool.extra.mail.Mail; import cn.hutool.extra.mail.MailAccount; +import cn.odboy.constant.SystemConst; import cn.odboy.framework.exception.BadRequestException; import cn.odboy.framework.properties.AppProperties; import cn.odboy.framework.redis.KitRedisHelper; @@ -32,7 +33,6 @@ import cn.odboy.util.KitResourceTemplateUtil; import java.util.Collections; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -46,8 +46,6 @@ public class SystemEmailService { private KitRedisHelper redisHelper; @Autowired private AppProperties properties; - @Value("${spring.application.title}") - private String applicationTitle; /** * 更新邮件配置 @@ -146,7 +144,7 @@ public class SystemEmailService { KitResourceTemplateUtil.render(null, biEnum.getTemplateName(), Dict.create().set("code", oldCode)); } SystemSendEmailArgs sendEmailRequest = - new SystemSendEmailArgs(Collections.singletonList(email), applicationTitle, content); + new SystemSendEmailArgs(Collections.singletonList(email), SystemConst.CURRENT_APP_TITLE, content); sendEmail(sendEmailRequest); } diff --git a/cutejava/cutejava-starter/src/main/resources/application-dev.yml b/cutejava/cutejava-starter/src/main/resources/application-dev.yml index 2ae209c7..12858f14 100644 --- a/cutejava/cutejava-starter/src/main/resources/application-dev.yml +++ b/cutejava/cutejava-starter/src/main/resources/application-dev.yml @@ -29,10 +29,6 @@ server: # GRACEFUL (优雅): 当应用程序以"GRACEFUL"模式关闭时,它不会接受新的请求且会尝试完成所有正在进行的请求和处理,然后才会终止。这种方式适用于那些可能需要一些时间来清理资源或完成正在进行的任务的场景。 # IMMEDIATE(立即): 当应用程序以"IMMEDIATE"模式关闭时,它会立即终止,而不管当前是否有任何活动任务或请求。这种方式适用于那些可以立即停止而不会造成严重问题的情况。 shutdown: graceful -spring: - application: - name: cutejava - title: CuteJava lifecycle: # 采用java.time.Duration格式的值,如果在这个时间内,优雅停机没有停掉应用,超过这个时间就会强制停止应用 timeout-per-shutdown-phase: 30s diff --git a/cutejava/cutejava-starter/src/main/resources/application-prod.yml b/cutejava/cutejava-starter/src/main/resources/application-prod.yml index 82fa762e..349f37d7 100644 --- a/cutejava/cutejava-starter/src/main/resources/application-prod.yml +++ b/cutejava/cutejava-starter/src/main/resources/application-prod.yml @@ -29,10 +29,6 @@ server: # GRACEFUL (优雅): 当应用程序以"GRACEFUL"模式关闭时,它不会接受新的请求且会尝试完成所有正在进行的请求和处理,然后才会终止。这种方式适用于那些可能需要一些时间来清理资源或完成正在进行的任务的场景。 # IMMEDIATE(立即): 当应用程序以"IMMEDIATE"模式关闭时,它会立即终止,而不管当前是否有任何活动任务或请求。这种方式适用于那些可以立即停止而不会造成严重问题的情况。 shutdown: graceful -spring: - application: - name: cutejava - title: CuteJava lifecycle: # 采用java.time.Duration格式的值,如果在这个时间内,优雅停机没有停掉应用,超过这个时间就会强制停止应用 timeout-per-shutdown-phase: 30s diff --git a/cutejava/cutejava-starter/src/main/resources/application-quartz.yml b/cutejava/cutejava-starter/src/main/resources/application-quartz.yml index 35ba2188..dc34ad0e 100644 --- a/cutejava/cutejava-starter/src/main/resources/application-quartz.yml +++ b/cutejava/cutejava-starter/src/main/resources/application-quartz.yml @@ -9,7 +9,7 @@ spring: quartz: scheduler: # 必需,指定调度器实例的名称 - instanceName: ${spring.application.name} + instanceName: cutejava # 必需,指定调度器实例的 ID instanceId: auto threadPool: