简化配置
This commit is contained in:
parent
7aca1d5163
commit
fe12305ec2
|
@ -1,10 +0,0 @@
|
|||
package io.metersphere.commons.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public interface MybatisInterceptorConfigHolder {
|
||||
default List<MybatisInterceptorConfig> interceptorConfig() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
|
@ -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<MybatisInterceptorConfig> interceptorConfig() {
|
||||
return Arrays.asList(
|
||||
new MybatisInterceptorConfig("io.metersphere.base.domain.FileContent", "file", "io.metersphere.commons.utils.CompressUtils", "zip", "unzip")
|
||||
);
|
||||
}
|
||||
}
|
|
@ -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<MybatisInterceptorConfig> 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<String, MybatisInterceptorConfigHolder> 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());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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;
|
Loading…
Reference in New Issue