Bladeren bron

系统优化

woody 11 maanden geleden
bovenliggende
commit
4530394102
17 gewijzigde bestanden met toevoegingen van 67 en 87 verwijderingen
  1. 4 2
      framework-base/src/main/java/com/chelvc/framework/base/config/JacksonConfigurer.java
  2. 0 15
      framework-base/src/main/java/com/chelvc/framework/base/context/ApplicationContextHolder.java
  3. 2 2
      framework-common/src/main/java/com/chelvc/framework/common/annotation/Sensitive.java
  4. 0 27
      framework-common/src/main/java/com/chelvc/framework/common/util/AESUtils.java
  5. 5 0
      framework-database/src/main/java/com/chelvc/framework/database/config/DatabaseProperties.java
  6. 1 1
      framework-database/src/main/java/com/chelvc/framework/database/config/TypeHandlerConfigurer.java
  7. 8 3
      framework-database/src/main/java/com/chelvc/framework/database/context/DatabaseContextHolder.java
  8. 1 1
      framework-database/src/main/java/com/chelvc/framework/database/handler/JsonTypeHandler.java
  9. 3 0
      framework-database/src/main/java/com/chelvc/framework/database/interceptor/DynamicInvokeInterceptor.java
  10. 4 4
      framework-export/src/main/java/com/chelvc/framework/export/support/DefaultExportHandler.java
  11. 4 4
      framework-nacos/src/main/java/com/chelvc/framework/nacos/config/MultiserverNacosConfigurer.java
  12. 6 7
      framework-redis/src/main/java/com/chelvc/framework/redis/config/RedisConfigurer.java
  13. 6 7
      framework-rocketmq/src/main/java/com/chelvc/framework/rocketmq/config/RocketMQConfigurer.java
  14. 5 0
      framework-security/src/main/java/com/chelvc/framework/security/config/SecurityProperties.java
  15. 6 2
      framework-security/src/main/java/com/chelvc/framework/security/interceptor/ControllerCryptoInterceptor.java
  16. 5 5
      framework-security/src/main/java/com/chelvc/framework/security/interceptor/PermissionValidateInterceptor.java
  17. 7 7
      framework-wechat/src/main/java/com/chelvc/framework/wechat/context/WechatContextHolder.java

+ 4 - 2
framework-base/src/main/java/com/chelvc/framework/base/config/JacksonConfigurer.java

@@ -2,6 +2,7 @@ package com.chelvc.framework.base.config;
 
 import com.chelvc.framework.common.util.JacksonUtils;
 import com.fasterxml.jackson.databind.ObjectMapper;
+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;
@@ -17,7 +18,8 @@ import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
 public class JacksonConfigurer {
     @Bean
     @Primary
-    public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
-        return JacksonUtils.initializeSerializer(builder.build(), true);
+    public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder,
+                                     @Value("${spring.jackson.safely:true}") boolean safely) {
+        return JacksonUtils.initializeSerializer(builder.build(), safely);
     }
 }

+ 0 - 15
framework-base/src/main/java/com/chelvc/framework/base/context/ApplicationContextHolder.java

@@ -390,21 +390,6 @@ public class ApplicationContextHolder implements ApplicationContextAware, Proper
                 .distinct().collect(Collectors.toList());
     }
 
-    /**
-     * 注册对象实例
-     *
-     * @param index    对象序号
-     * @param type     对象类型
-     * @param supplier 对象实例提供函数
-     * @param <T>      对象类型泛型
-     * @return 对象实例
-     */
-    public static <T> T register(int index, @NonNull Class<T> type, @NonNull Supplier<T> supplier) {
-        AssertUtils.check(index > -1, () -> "Bean index must be greater than -1");
-        String name = type.getName() + "_" + index;
-        return register(name, type, supplier);
-    }
-
     /**
      * 注册对象实例
      *

+ 2 - 2
framework-database/src/main/java/com/chelvc/framework/database/annotation/Sensitive.java → framework-common/src/main/java/com/chelvc/framework/common/annotation/Sensitive.java

@@ -1,4 +1,4 @@
-package com.chelvc.framework.database.annotation;
+package com.chelvc.framework.common.annotation;
 
 import java.lang.annotation.Documented;
 import java.lang.annotation.ElementType;
@@ -15,7 +15,7 @@ import java.lang.annotation.Target;
  */
 @Inherited
 @Documented
-@Target(ElementType.FIELD)
 @Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.FIELD, ElementType.METHOD})
 public @interface Sensitive {
 }

+ 0 - 27
framework-common/src/main/java/com/chelvc/framework/common/util/AESUtils.java

@@ -5,7 +5,6 @@ import java.security.GeneralSecurityException;
 import java.security.Key;
 import java.security.NoSuchAlgorithmException;
 import java.security.Security;
-import java.util.Arrays;
 import java.util.Map;
 import java.util.function.Supplier;
 import javax.crypto.Cipher;
@@ -17,7 +16,6 @@ import com.chelvc.framework.common.model.Pool;
 import com.google.common.collect.Maps;
 import lombok.NonNull;
 import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.lang3.tuple.Pair;
 import org.bouncycastle.jce.provider.BouncyCastleProvider;
 
 /**
@@ -74,17 +72,6 @@ public final class AESUtils {
     private AESUtils() {
     }
 
-    /**
-     * 根据密钥获取默认的CBC加解密凭证信息
-     *
-     * @param secret 密钥
-     * @return 密钥/向量部分
-     */
-    public static Pair<byte[], byte[]> getDefaultCBCCertificate(@NonNull String secret) {
-        byte[] bytes = secret.getBytes(StandardCharsets.UTF_8);
-        return Pair.of(bytes, Arrays.copyOfRange(bytes, 0, 16));
-    }
-
     /**
      * 获取密码处理器
      *
@@ -208,20 +195,6 @@ public final class AESUtils {
         return pool.get();
     }
 
-    /**
-     * 从缓存中查找默认密码处理器,如果不存在则新建
-     *
-     * @param mode   加解密模式
-     * @param secret 密钥
-     * @return 处理器实例
-     */
-    public static Cipher lookupDefaultCipher(int mode, @NonNull String secret) {
-        return lookupCipher(CBC_PKCS5PADDING + secret, mode, () -> {
-            Pair<byte[], byte[]> pair = getDefaultCBCCertificate(secret);
-            return getCipher(CBC_PKCS5PADDING, mode, pair.getLeft(), pair.getRight());
-        });
-    }
-
     /**
      * 获取加密处理器
      *

+ 5 - 0
framework-database/src/main/java/com/chelvc/framework/database/config/DatabaseProperties.java

@@ -29,6 +29,11 @@ public class DatabaseProperties {
          */
         private String secret;
 
+        /**
+         * 加解密初始向量
+         */
+        private String iv;
+
         /**
          * 字段是否同时包含明文和明文,如果包含则在使用该字段精确匹配时自动加入明文查询条件
          */

+ 1 - 1
framework-database/src/main/java/com/chelvc/framework/database/config/TypeHandlerConfigurer.java

@@ -35,13 +35,13 @@ import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
 import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import com.chelvc.framework.common.annotation.Sensitive;
 import com.chelvc.framework.common.model.File;
 import com.chelvc.framework.common.model.Modification;
 import com.chelvc.framework.common.model.Period;
 import com.chelvc.framework.common.model.Region;
 import com.chelvc.framework.common.util.ObjectUtils;
 import com.chelvc.framework.common.util.StringUtils;
-import com.chelvc.framework.database.annotation.Sensitive;
 import com.chelvc.framework.database.handler.BooleanArrayTypeHandler;
 import com.chelvc.framework.database.handler.BooleanSetTypeHandler;
 import com.chelvc.framework.database.handler.BooleansTypeHandler;

+ 8 - 3
framework-database/src/main/java/com/chelvc/framework/database/context/DatabaseContextHolder.java

@@ -29,6 +29,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.chelvc.framework.base.context.ApplicationContextHolder;
 import com.chelvc.framework.base.util.SpringUtils;
+import com.chelvc.framework.common.annotation.Sensitive;
 import com.chelvc.framework.common.function.Executor;
 import com.chelvc.framework.common.function.Handler;
 import com.chelvc.framework.common.function.Provider;
@@ -37,7 +38,6 @@ import com.chelvc.framework.common.model.Paging;
 import com.chelvc.framework.common.util.AESUtils;
 import com.chelvc.framework.common.util.AssertUtils;
 import com.chelvc.framework.common.util.ObjectUtils;
-import com.chelvc.framework.database.annotation.Sensitive;
 import com.chelvc.framework.database.config.DatabaseProperties;
 import com.chelvc.framework.database.entity.Entity;
 import com.chelvc.framework.database.support.EventService;
@@ -120,8 +120,13 @@ public final class DatabaseContextHolder {
      * @return 密码处理器实例
      */
     private static Cipher getCipher(int mode) {
-        String secret = AssertUtils.nonempty(getProperties().getSensitive().getSecret(), () -> "Secret is missing");
-        return AESUtils.lookupDefaultCipher(mode, secret);
+        DatabaseProperties.Sensitive sensitive = getProperties().getSensitive();
+        String secret = AssertUtils.nonempty(sensitive.getSecret(), () -> "Sensitive secret is missing");
+        String iv = AssertUtils.nonempty(sensitive.getIv(), () -> "Sensitive iv is missing");
+        return AESUtils.lookupCipher(
+                AESUtils.CBC_PKCS5PADDING + secret, mode,
+                () -> AESUtils.getCipher(AESUtils.CBC_PKCS5PADDING, mode, secret, iv)
+        );
     }
 
     /**

+ 1 - 1
framework-database/src/main/java/com/chelvc/framework/database/handler/JsonTypeHandler.java

@@ -14,9 +14,9 @@ import java.sql.Types;
 import java.util.List;
 import java.util.Set;
 
+import com.chelvc.framework.common.annotation.Sensitive;
 import com.chelvc.framework.common.util.JacksonUtils;
 import com.chelvc.framework.common.util.ObjectUtils;
-import com.chelvc.framework.database.annotation.Sensitive;
 import com.chelvc.framework.database.context.DatabaseContextHolder;
 import com.fasterxml.jackson.core.JsonGenerator;
 import com.fasterxml.jackson.core.JsonParser;

+ 3 - 0
framework-database/src/main/java/com/chelvc/framework/database/interceptor/DynamicInvokeInterceptor.java

@@ -435,6 +435,9 @@ public class DynamicInvokeInterceptor implements Interceptor {
             if (ObjectUtils.notEmpty(plain.getJoins())) {
                 changed |= this.prepareJdbcParameter(plain, plain.getJoins(), consumer);
             }
+            if (plain.getFromItem() != null && !(plain.getFromItem() instanceof Table)) {
+                changed |= this.prepareJdbcParameter(plain, plain.getFromItem(), consumer);
+            }
         } else if (model instanceof LateralSubSelect) {
             LateralSubSelect lateral = (LateralSubSelect) model;
             if (lateral.getSubSelect() != null) {

+ 4 - 4
framework-export/src/main/java/com/chelvc/framework/export/support/DefaultExportHandler.java

@@ -32,8 +32,8 @@ import lombok.NonNull;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.xssf.streaming.SXSSFWorkbook;
-import org.springframework.boot.ApplicationArguments;
-import org.springframework.boot.ApplicationRunner;
+import org.springframework.boot.context.event.ApplicationStartedEvent;
+import org.springframework.context.ApplicationListener;
 import org.springframework.data.redis.core.RedisTemplate;
 
 /**
@@ -43,7 +43,7 @@ import org.springframework.data.redis.core.RedisTemplate;
  * @date 2024/5/9
  */
 @Slf4j
-public class DefaultExportHandler implements ExportHandler, ApplicationRunner {
+public class DefaultExportHandler implements ExportHandler, ApplicationListener<ApplicationStartedEvent> {
     private final String directory;
     private final Duration duration;
     private final RedisTemplate<String, Object> redisTemplate;
@@ -124,7 +124,7 @@ public class DefaultExportHandler implements ExportHandler, ApplicationRunner {
     }
 
     @Override
-    public void run(ApplicationArguments args) throws Exception {
+    public void onApplicationEvent(ApplicationStartedEvent event) {
         // 初始化导出文件清理线程
         ThreadUtils.run(() -> {
             log.info("Export file cleaner running...");

+ 4 - 4
framework-nacos/src/main/java/com/chelvc/framework/nacos/config/MultiserverNacosConfigurer.java

@@ -7,9 +7,9 @@ import com.chelvc.framework.base.context.ApplicationContextHolder;
 import com.chelvc.framework.common.util.StringUtils;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.ApplicationArguments;
-import org.springframework.boot.ApplicationRunner;
+import org.springframework.boot.context.event.ApplicationStartedEvent;
 import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationListener;
 import org.springframework.core.io.Resource;
 
 /**
@@ -21,13 +21,13 @@ import org.springframework.core.io.Resource;
  * @date 2024/1/30
  */
 @RequiredArgsConstructor(onConstructor = @__(@Autowired))
-public class MultiserverNacosConfigurer implements ApplicationRunner {
+public class MultiserverNacosConfigurer implements ApplicationListener<ApplicationStartedEvent> {
     private final NacosServiceRegistry registry;
     private final NacosDiscoveryProperties properties;
     private final ApplicationContext applicationContext;
 
     @Override
-    public void run(ApplicationArguments args) {
+    public void onApplicationEvent(ApplicationStartedEvent event) {
         String applicationName = ApplicationContextHolder.getApplicationName(this.applicationContext);
         for (Resource resource : ApplicationContextHolder.getApplicationResources()) {
             // 将打包的服务注册到nacos(排除当前服务)

+ 6 - 7
framework-redis/src/main/java/com/chelvc/framework/redis/config/RedisConfigurer.java

@@ -2,12 +2,12 @@ package com.chelvc.framework.redis.config;
 
 import java.lang.reflect.Type;
 import java.time.Duration;
-import java.util.concurrent.atomic.AtomicInteger;
 
 import com.chelvc.framework.base.context.ApplicationContextHolder;
 import com.chelvc.framework.common.util.AssertUtils;
 import com.chelvc.framework.common.util.JacksonUtils;
 import com.chelvc.framework.common.util.ObjectUtils;
+import com.chelvc.framework.common.util.StringUtils;
 import com.chelvc.framework.redis.annotation.RedisMQConsumer;
 import com.chelvc.framework.redis.stream.DefaultRedisMQListenerContainer;
 import com.chelvc.framework.redis.stream.RedisMQListener;
@@ -27,14 +27,14 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.springframework.aop.framework.AopProxyUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.ApplicationArguments;
-import org.springframework.boot.ApplicationRunner;
 import org.springframework.boot.autoconfigure.AutoConfigureAfter;
 import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
+import org.springframework.boot.context.event.ApplicationStartedEvent;
 import org.springframework.cache.CacheManager;
 import org.springframework.cache.annotation.CachingConfigurerSupport;
 import org.springframework.cache.annotation.EnableCaching;
 import org.springframework.cache.interceptor.KeyGenerator;
+import org.springframework.context.ApplicationListener;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Primary;
 import org.springframework.core.task.TaskExecutor;
@@ -60,11 +60,10 @@ import org.springframework.stereotype.Component;
 @EnableCaching
 @AutoConfigureAfter(RedisAutoConfiguration.class)
 @RequiredArgsConstructor(onConstructor = @__(@Autowired))
-public class RedisConfigurer extends CachingConfigurerSupport implements ApplicationRunner {
+public class RedisConfigurer extends CachingConfigurerSupport implements ApplicationListener<ApplicationStartedEvent> {
     private final TaskExecutor executor;
     private final ClientResources clientResources;
     private final LettuceConnectionFactory connectionFactory;
-    private final AtomicInteger counter = new AtomicInteger(0);
 
     /**
      * 注册消息监听器容器
@@ -81,7 +80,7 @@ public class RedisConfigurer extends CachingConfigurerSupport implements Applica
         );
         Type type = ObjectUtils.lookupSuperclassParameterized(clazz, RedisMQListener.class, Object.class);
         RedisMQListenerContainer<T> container = ApplicationContextHolder.register(
-                this.counter.incrementAndGet(), RedisMQListenerContainer.class, DefaultRedisMQListenerContainer::new
+                StringUtils.uuid(), RedisMQListenerContainer.class, DefaultRedisMQListenerContainer::new
         );
         try {
             container.initialize(type, listener, annotation);
@@ -92,7 +91,7 @@ public class RedisConfigurer extends CachingConfigurerSupport implements Applica
 
     @Override
     @SuppressWarnings("unchecked")
-    public void run(ApplicationArguments args) throws Exception {
+    public void onApplicationEvent(ApplicationStartedEvent event) {
         // Redis事件配置
         EventBus bus = this.clientResources.eventBus();
         ApplicationContextHolder.getBeans(RedisEventConfigurerAdapter.class).forEach(

+ 6 - 7
framework-rocketmq/src/main/java/com/chelvc/framework/rocketmq/config/RocketMQConfigurer.java

@@ -1,11 +1,11 @@
 package com.chelvc.framework.rocketmq.config;
 
 import java.lang.reflect.Type;
-import java.util.concurrent.atomic.AtomicInteger;
 
 import com.chelvc.framework.base.context.ApplicationContextHolder;
 import com.chelvc.framework.common.util.AssertUtils;
 import com.chelvc.framework.common.util.ObjectUtils;
+import com.chelvc.framework.common.util.StringUtils;
 import com.chelvc.framework.rocketmq.annotation.RocketMQConsumer;
 import com.chelvc.framework.rocketmq.consumer.MultipleRocketMQListenerContainer;
 import com.chelvc.framework.rocketmq.consumer.RocketMQListener;
@@ -21,8 +21,8 @@ import org.apache.rocketmq.client.apis.SessionCredentialsProvider;
 import org.apache.rocketmq.client.apis.StaticSessionCredentialsProvider;
 import org.springframework.aop.framework.AopProxyUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.ApplicationArguments;
-import org.springframework.boot.ApplicationRunner;
+import org.springframework.boot.context.event.ApplicationStartedEvent;
+import org.springframework.context.ApplicationListener;
 import org.springframework.context.annotation.Bean;
 import org.springframework.stereotype.Component;
 
@@ -35,9 +35,8 @@ import org.springframework.stereotype.Component;
 @Slf4j
 @Component
 @RequiredArgsConstructor(onConstructor = @__(@Autowired))
-public class RocketMQConfigurer implements ApplicationRunner {
+public class RocketMQConfigurer implements ApplicationListener<ApplicationStartedEvent> {
     private final RocketMQProperties properties;
-    private final AtomicInteger counter = new AtomicInteger(0);
 
     @Bean
     public ClientServiceProvider provider() {
@@ -72,7 +71,7 @@ public class RocketMQConfigurer implements ApplicationRunner {
         );
         Type type = ObjectUtils.lookupSuperclassParameterized(clazz, RocketMQListener.class, Object.class);
         RocketMQListenerContainer<T> container = ApplicationContextHolder.register(
-                this.counter.incrementAndGet(), RocketMQListenerContainer.class, () -> {
+                StringUtils.uuid(), RocketMQListenerContainer.class, () -> {
                     boolean multiple = Math.max(annotation.batch(), 1) > 1;
                     return multiple ? new MultipleRocketMQListenerContainer<>() :
                             new SingleRocketMQListenerContainer<>();
@@ -86,7 +85,7 @@ public class RocketMQConfigurer implements ApplicationRunner {
 
     @Override
     @SuppressWarnings("unchecked")
-    public void run(ApplicationArguments args) throws Exception {
+    public void onApplicationEvent(ApplicationStartedEvent event) {
         // 注册消息监听器
         ApplicationContextHolder.getBeans(RocketMQListener.class).forEach(
                 (key, listener) -> this.registerListenerContainer(listener)

+ 5 - 0
framework-security/src/main/java/com/chelvc/framework/security/config/SecurityProperties.java

@@ -19,6 +19,11 @@ public class SecurityProperties {
      */
     private String secret;
 
+    /**
+     * 加解密初始向量
+     */
+    private String iv;
+
     /**
      * 请求时长(毫秒)
      */

+ 6 - 2
framework-security/src/main/java/com/chelvc/framework/security/interceptor/ControllerCryptoInterceptor.java

@@ -51,8 +51,12 @@ public class ControllerCryptoInterceptor extends RequestBodyAdviceAdapter implem
      * @return 密码处理器实例
      */
     private Cipher getCipher(int mode) {
-        String secret = AssertUtils.nonempty(this.properties.getSecret(), () -> "Secret is missing");
-        return AESUtils.lookupDefaultCipher(mode, secret);
+        String secret = AssertUtils.nonempty(this.properties.getSecret(), () -> "Crypto secret is missing");
+        String iv = AssertUtils.nonempty(this.properties.getIv(), () -> "Crypto iv is missing");
+        return AESUtils.lookupCipher(
+                AESUtils.CBC_PKCS5PADDING + secret, mode,
+                () -> AESUtils.getCipher(AESUtils.CBC_PKCS5PADDING, mode, secret, iv)
+        );
     }
 
     /**

+ 5 - 5
framework-security/src/main/java/com/chelvc/framework/security/interceptor/PermissionValidateInterceptor.java

@@ -16,9 +16,9 @@ import com.google.common.collect.Sets;
 import lombok.RequiredArgsConstructor;
 import org.springframework.aop.framework.AopProxyUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.ApplicationArguments;
-import org.springframework.boot.ApplicationRunner;
+import org.springframework.boot.context.event.ApplicationStartedEvent;
 import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationListener;
 import org.springframework.core.Ordered;
 import org.springframework.http.HttpStatus;
 import org.springframework.stereotype.Component;
@@ -35,7 +35,8 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  */
 @Component
 @RequiredArgsConstructor(onConstructor = @__(@Autowired))
-public class PermissionValidateInterceptor implements ApplicationRunner, HandlerInterceptor, WebMvcConfigurer {
+public class PermissionValidateInterceptor implements HandlerInterceptor, WebMvcConfigurer,
+        ApplicationListener<ApplicationStartedEvent> {
     private final ApplicationContext applicationContext;
 
     /**
@@ -52,7 +53,7 @@ public class PermissionValidateInterceptor implements ApplicationRunner, Handler
     }
 
     @Override
-    public void run(ApplicationArguments args) throws Exception {
+    public void onApplicationEvent(ApplicationStartedEvent event) {
         // 检查权限标识是否重复
         List<Object> controllers = ApplicationContextHolder.lookupControllers(this.applicationContext);
         if (ObjectUtils.isEmpty(controllers)) {
@@ -75,7 +76,6 @@ public class PermissionValidateInterceptor implements ApplicationRunner, Handler
     }
 
     @Override
-    @SuppressWarnings("unchecked")
     public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
             throws Exception {
         Permission annotation = this.getPermissionAnnotation(handler);

+ 7 - 7
framework-wechat/src/main/java/com/chelvc/framework/wechat/context/WechatContextHolder.java

@@ -26,9 +26,8 @@ import com.google.common.collect.Maps;
 import lombok.NonNull;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.lang3.tuple.Pair;
-import org.springframework.boot.ApplicationArguments;
-import org.springframework.boot.ApplicationRunner;
+import org.springframework.boot.context.event.ApplicationStartedEvent;
+import org.springframework.context.ApplicationListener;
 import org.springframework.core.ParameterizedTypeReference;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpMethod;
@@ -43,7 +42,7 @@ import org.springframework.web.client.RestTemplate;
  */
 @Slf4j
 @Component
-public final class WechatContextHolder implements ApplicationRunner {
+public final class WechatContextHolder implements ApplicationListener<ApplicationStartedEvent> {
     /**
      * 获取访问令牌接口地址
      */
@@ -69,7 +68,7 @@ public final class WechatContextHolder implements ApplicationRunner {
     }
 
     @Override
-    public void run(ApplicationArguments args) throws Exception {
+    public void onApplicationEvent(ApplicationStartedEvent event) {
         if (!this.initialized) {
             synchronized (this) {
                 if (!this.initialized) {
@@ -271,8 +270,9 @@ public final class WechatContextHolder implements ApplicationRunner {
 
         // 解密数据
         Cipher cipher = AESUtils.lookupDecrypter(AESUtils.CBC_NOPADDING + secret, () -> {
-            Pair<byte[], byte[]> pair = AESUtils.getDefaultCBCCertificate(secret);
-            return AESUtils.getCipher(AESUtils.CBC_NOPADDING, Cipher.DECRYPT_MODE, pair.getLeft(), pair.getRight());
+            byte[] bytes = secret.getBytes(StandardCharsets.UTF_8);
+            byte[] iv = Arrays.copyOfRange(bytes, 0, 16);
+            return AESUtils.getCipher(AESUtils.CBC_NOPADDING, Cipher.DECRYPT_MODE, bytes, iv);
         });
         byte[] original = AESUtils.codec(cipher, Base64.decodeBase64(ciphertext));