io.github.dengchen2020.mybatis.config.MybatisAutoConfiguration Maven / Gradle / Ivy
package io.github.dengchen2020.mybatis.config;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import io.github.dengchen2020.mybatis.injector.DcSqlInjector;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
/**
* mybatis自动配置
*
* @author dengchen
* @since 2024/6/22
*/
@PropertySource("classpath:application-mybatis.properties")
@Configuration(proxyBeanMethods = false)
public class MybatisAutoConfiguration {
@ConditionalOnMissingBean
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
return interceptor;
}
@ConditionalOnMissingBean
@Bean
public DcSqlInjector dcSqlInjector() {
return new DcSqlInjector();
}
}