mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-06 16:48:24 +08:00
feat: 新增 MyBatisFlexInitializer.java 方便用户对 MyBatisFlex 进行初始化配置
This commit is contained in:
parent
039ef607b3
commit
037f0efc78
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.mybatisflex.spring.boot;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MyBatisFlex 初始化监听器
|
||||||
|
* 一般可以用于去初始化:
|
||||||
|
*
|
||||||
|
* 1、自定义主键生成器
|
||||||
|
* 2、FlexGlobalConfig 的全局配置
|
||||||
|
* 3、多租户配置
|
||||||
|
* 4、动态表名配置
|
||||||
|
* 5、逻辑删除处理器配置
|
||||||
|
* 6、自定义脱敏规则
|
||||||
|
* 7、SQL 审计配置
|
||||||
|
* 8、SQL 打印配置
|
||||||
|
* 9、数据源解密器配置
|
||||||
|
* 10、自定义数据方言配置
|
||||||
|
* ...
|
||||||
|
*/
|
||||||
|
public interface MyBatisFlexInitializer {
|
||||||
|
void onInitBefore();
|
||||||
|
}
|
||||||
@ -121,6 +121,9 @@ public class MybatisFlexAutoConfiguration implements InitializingBean {
|
|||||||
//多租户
|
//多租户
|
||||||
protected final TenantFactory tenantFactory;
|
protected final TenantFactory tenantFactory;
|
||||||
|
|
||||||
|
//初始化监听
|
||||||
|
protected final MyBatisFlexInitializer myBatisFlexInitializer;
|
||||||
|
|
||||||
|
|
||||||
public MybatisFlexAutoConfiguration(MybatisFlexProperties properties, ObjectProvider<Interceptor[]> interceptorsProvider,
|
public MybatisFlexAutoConfiguration(MybatisFlexProperties properties, ObjectProvider<Interceptor[]> interceptorsProvider,
|
||||||
ObjectProvider<TypeHandler[]> typeHandlersProvider, ObjectProvider<LanguageDriver[]> languageDriversProvider,
|
ObjectProvider<TypeHandler[]> typeHandlersProvider, ObjectProvider<LanguageDriver[]> languageDriversProvider,
|
||||||
@ -130,7 +133,8 @@ public class MybatisFlexAutoConfiguration implements InitializingBean {
|
|||||||
ObjectProvider<DataSourceDecipher> dataSourceDecipherProvider,
|
ObjectProvider<DataSourceDecipher> dataSourceDecipherProvider,
|
||||||
ObjectProvider<DynamicTableProcessor> dynamicTableProcessorProvider,
|
ObjectProvider<DynamicTableProcessor> dynamicTableProcessorProvider,
|
||||||
ObjectProvider<DynamicSchemaProcessor> dynamicSchemaProcessorProvider,
|
ObjectProvider<DynamicSchemaProcessor> dynamicSchemaProcessorProvider,
|
||||||
ObjectProvider<TenantFactory> tenantFactoryProvider
|
ObjectProvider<TenantFactory> tenantFactoryProvider,
|
||||||
|
ObjectProvider<MyBatisFlexInitializer> myBatisFlexInitializerProvider
|
||||||
) {
|
) {
|
||||||
this.properties = properties;
|
this.properties = properties;
|
||||||
this.interceptors = interceptorsProvider.getIfAvailable();
|
this.interceptors = interceptorsProvider.getIfAvailable();
|
||||||
@ -150,6 +154,9 @@ public class MybatisFlexAutoConfiguration implements InitializingBean {
|
|||||||
|
|
||||||
//多租户
|
//多租户
|
||||||
this.tenantFactory = tenantFactoryProvider.getIfAvailable();
|
this.tenantFactory = tenantFactoryProvider.getIfAvailable();
|
||||||
|
|
||||||
|
//初始化监听器
|
||||||
|
this.myBatisFlexInitializer = myBatisFlexInitializerProvider.getIfAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -174,6 +181,11 @@ public class MybatisFlexAutoConfiguration implements InitializingBean {
|
|||||||
if (tenantFactory != null) {
|
if (tenantFactory != null) {
|
||||||
TenantManager.setTenantFactory(tenantFactory);
|
TenantManager.setTenantFactory(tenantFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//初始化监听器
|
||||||
|
if (myBatisFlexInitializer != null) {
|
||||||
|
myBatisFlexInitializer.onInitBefore();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkConfigFileExists() {
|
private void checkConfigFileExists() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user