当前使用版本(必须填写清楚,否则不予处理)
2.3
该问题是怎么引起的?(最新版上已修复的会直接close掉)
比如:
mybatis-plus.configuration.interceptors=com.XxxInterceptor
重现步骤
报错信息
Comment From: miemieYaho
@bean 注入
Comment From: bestK
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor(DataScopeService dataScopeService, MPInterceptorProperties properties) {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
DataScopeInnerInterceptor dataScopeInnerInterceptor = new DataScopeInnerInterceptor(dataScopeService);
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
paginationInnerInterceptor.setMaxLimit(500L);
TableTrashInnerInterceptor tableTrashInnerInterceptor = new TableTrashInnerInterceptor();
interceptor.addInnerInterceptor(dataScopeInnerInterceptor);
interceptor.addInnerInterceptor(paginationInnerInterceptor);
interceptor.addInnerInterceptor(tableTrashInnerInterceptor);
// 从 nacos 中获取属性配置拦截器
if (null != properties.getInterceptorProperties()) {
interceptor.setProperties(properties.getInterceptorProperties());
}
return interceptor;
}
/**
* mybatis plus 拦截器属性
* @author liukl
* @since 2023-1-19 10:41:19
*/
@Data
@ConfigurationProperties(prefix = "mybatis-plus.configuration")
public class MPInterceptorProperties {
final String AT = "_AT_";
final String COLON = "_COLON_";
private boolean replaced;
/**
* 使用内部规则,拿分页插件举个栗子:
* <p>
* - key: "@page" ,value: "com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor"
* - key: "page:limit" ,value: "100"
* <p>
* 解读1: key 以 "@" 开头定义了这是一个需要组装的 `InnerInterceptor`, 以 "page" 结尾表示别名
* value 是 `InnerInterceptor` 的具体的 class 全名
* 解读2: key 以上面定义的 "别名 + ':'" 开头指这个 `value` 是定义的该 `InnerInterceptor` 属性需要设置的值
* <p>
* 如果这个 `InnerInterceptor` 不需要配置属性也要加别名
*
* <pre>
* nacos 配置示例
* mybatis-plus:
* configuration:
* interceptor-properties:
* # _AT_代表 @ _COLON_ 代表 : 冒号
* # _AT_optimisticLocker 等价于 @optimisticLocker , optimisticLocker_COLON_id 等价于 optimisticLocker:id
* "_AT_optimisticLocker": com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor
* "table-trash_COLON_userid-method": cn.dian1.utils.UserUtils.getCurrentUserId
* </pre>
*/
Properties interceptorProperties;
public Properties getInterceptorProperties() {
if (!replaced && interceptorProperties != null) {
Properties prop = new Properties();
for (Object key : interceptorProperties.keySet()) {
String tempKey = key.toString().replace(AT, StringPool.AT).replace(COLON, ":");
prop.put(tempKey, interceptorProperties.get(key));
}
this.interceptorProperties = prop;
replaced = true;
}
return interceptorProperties;
}
}
mybatis-plus:
configuration:
interceptor-properties:
# _AT_代表 @ _COLON_ 代表 : 冒号
"_AT_optimisticLocker": com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor