From fe12305ec24e0d2fbde7049882274663eca54d05 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Tue, 25 Feb 2020 14:29:01 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8C=96=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utils/MybatisInterceptorConfigHolder.java | 10 ------- .../metersphere/config/DBEncryptConfig.java | 18 ----------- .../io/metersphere/config/MybatisConfig.java | 30 ++----------------- .../MybatisInterceptor.java | 4 ++- 4 files changed, 5 insertions(+), 57 deletions(-) delete mode 100644 backend/src/main/java/io/metersphere/commons/utils/MybatisInterceptorConfigHolder.java delete mode 100644 backend/src/main/java/io/metersphere/config/DBEncryptConfig.java rename backend/src/main/java/io/metersphere/{commons/utils => interceptor}/MybatisInterceptor.java (98%) diff --git a/backend/src/main/java/io/metersphere/commons/utils/MybatisInterceptorConfigHolder.java b/backend/src/main/java/io/metersphere/commons/utils/MybatisInterceptorConfigHolder.java deleted file mode 100644 index e366c7e472..0000000000 --- a/backend/src/main/java/io/metersphere/commons/utils/MybatisInterceptorConfigHolder.java +++ /dev/null @@ -1,10 +0,0 @@ -package io.metersphere.commons.utils; - -import java.util.ArrayList; -import java.util.List; - -public interface MybatisInterceptorConfigHolder { - default List interceptorConfig() { - return new ArrayList<>(); - } -} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/config/DBEncryptConfig.java b/backend/src/main/java/io/metersphere/config/DBEncryptConfig.java deleted file mode 100644 index ddaaff0c4e..0000000000 --- a/backend/src/main/java/io/metersphere/config/DBEncryptConfig.java +++ /dev/null @@ -1,18 +0,0 @@ -package io.metersphere.config; - -import io.metersphere.commons.utils.MybatisInterceptorConfig; -import io.metersphere.commons.utils.MybatisInterceptorConfigHolder; -import org.springframework.context.annotation.Configuration; - -import java.util.Arrays; -import java.util.List; - -@Configuration -public class DBEncryptConfig implements MybatisInterceptorConfigHolder { - @Override - public List interceptorConfig() { - return Arrays.asList( - new MybatisInterceptorConfig("io.metersphere.base.domain.FileContent", "file", "io.metersphere.commons.utils.CompressUtils", "zip", "unzip") - ); - } -} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/config/MybatisConfig.java b/backend/src/main/java/io/metersphere/config/MybatisConfig.java index c072dda608..b881f98eca 100644 --- a/backend/src/main/java/io/metersphere/config/MybatisConfig.java +++ b/backend/src/main/java/io/metersphere/config/MybatisConfig.java @@ -1,24 +1,17 @@ package io.metersphere.config; import com.github.pagehelper.PageInterceptor; -import io.metersphere.commons.utils.LogUtil; -import io.metersphere.commons.utils.MybatisInterceptor; import io.metersphere.commons.utils.MybatisInterceptorConfig; -import io.metersphere.commons.utils.MybatisInterceptorConfigHolder; +import io.metersphere.interceptor.MybatisInterceptor; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; -import org.springframework.context.event.ContextRefreshedEvent; -import org.springframework.context.event.EventListener; import org.springframework.transaction.annotation.EnableTransactionManagement; -import org.springframework.util.CollectionUtils; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.Properties; @Configuration @@ -46,27 +39,8 @@ public class MybatisConfig { public MybatisInterceptor dbInterceptor() { MybatisInterceptor interceptor = new MybatisInterceptor(); List configList = new ArrayList<>(); + configList.add(new MybatisInterceptorConfig("io.metersphere.base.domain.FileContent", "file", "io.metersphere.commons.utils.CompressUtils", "zip", "unzip")); interceptor.setInterceptorConfigList(configList); return interceptor; } - - /** - * 等到ApplicationContext 加载完成之后 装配MybatisInterceptorConfigHolder - */ - @EventListener - public void handleContextRefresh(ContextRefreshedEvent event) { - try { - ApplicationContext context = event.getApplicationContext(); - MybatisInterceptor dBEncryptInterceptor = context.getBean(MybatisInterceptor.class); - Map beansOfType = context.getBeansOfType(MybatisInterceptorConfigHolder.class); - for (MybatisInterceptorConfigHolder config : beansOfType.values()) { - if (!CollectionUtils.isEmpty(config.interceptorConfig())) { - dBEncryptInterceptor.getInterceptorConfigList().addAll(config.interceptorConfig()); - } - } - } catch (Exception e) { - LogUtil.error("装配Mybatis插件拦截配置错误,错误:" + e.getMessage()); - } - - } } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/commons/utils/MybatisInterceptor.java b/backend/src/main/java/io/metersphere/interceptor/MybatisInterceptor.java similarity index 98% rename from backend/src/main/java/io/metersphere/commons/utils/MybatisInterceptor.java rename to backend/src/main/java/io/metersphere/interceptor/MybatisInterceptor.java index a06876f149..13e0c92a98 100644 --- a/backend/src/main/java/io/metersphere/commons/utils/MybatisInterceptor.java +++ b/backend/src/main/java/io/metersphere/interceptor/MybatisInterceptor.java @@ -1,5 +1,7 @@ -package io.metersphere.commons.utils; +package io.metersphere.interceptor; +import io.metersphere.commons.utils.BeanUtils; +import io.metersphere.commons.utils.MybatisInterceptorConfig; import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.cache.CacheKey; import org.apache.ibatis.executor.Executor;