io.github.nichetoolkit.mybatis.configure.MybatisRecordAutoConfigure Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mybatis-toolkit-starter Show documentation
Show all versions of mybatis-toolkit-starter Show documentation
mybatis toolkit starter project for Spring Boot
package io.github.nichetoolkit.mybatis.configure;
import io.github.nichetoolkit.mybatis.record.MybatisRecordProvider;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
/**
* MybatisRecordAutoConfigure
* The mybatis record auto configure class.
* @author Cyan ([email protected])
* @see lombok.extern.slf4j.Slf4j
* @see org.springframework.boot.autoconfigure.AutoConfiguration
* @see org.springframework.context.annotation.ComponentScan
* @see org.springframework.boot.context.properties.EnableConfigurationProperties
* @see org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
* @since Jdk1.8
*/
@Slf4j
@AutoConfiguration
@ComponentScan(basePackages = {"io.github.nichetoolkit.mybatis"})
@EnableConfigurationProperties({MybatisRecordProperties.class})
@ConditionalOnProperty(prefix = "nichetoolkit.mybatis.record", name="enabled", havingValue = "true", matchIfMissing = true)
public class MybatisRecordAutoConfigure {
/**
* MybatisRecordAutoConfigure
* Instantiates a new mybatis record auto configure.
*/
public MybatisRecordAutoConfigure() {
log.debug("The auto configuration for [mybatis-record] initiated");
}
/**
* recordProvider
* The record provider method.
* @param sqlSessionTemplate {@link org.mybatis.spring.SqlSessionTemplate} The sql session template parameter is SqlSessionTemplate
type.
* @return {@link io.github.nichetoolkit.mybatis.record.MybatisRecordProvider} The record provider return object is MybatisRecordProvider
type.
* @see org.mybatis.spring.SqlSessionTemplate
* @see io.github.nichetoolkit.mybatis.record.MybatisRecordProvider
* @see org.springframework.context.annotation.Bean
* @see org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
*/
@Bean
@ConditionalOnMissingBean(MybatisRecordProvider.class)
public MybatisRecordProvider,?,?> recordProvider(SqlSessionTemplate sqlSessionTemplate) {
return new MybatisRecordProvider<>(sqlSessionTemplate);
}
/**
* MybatisRecordAutoRegister
* The mybatis record auto register class.
* @author Cyan ([email protected])
* @see org.springframework.beans.factory.InitializingBean
* @see org.springframework.boot.autoconfigure.AutoConfiguration
* @since Jdk1.8
*/
@AutoConfiguration
public static class MybatisRecordAutoRegister implements InitializingBean {
/**
* recordProvider
* {@link io.github.nichetoolkit.mybatis.record.MybatisRecordProvider} The recordProvider
field.
* @see io.github.nichetoolkit.mybatis.record.MybatisRecordProvider
*/
private final MybatisRecordProvider,?,?> recordProvider;
/**
* MybatisRecordAutoRegister
* Instantiates a new mybatis record auto register.
* @param recordProvider {@link io.github.nichetoolkit.mybatis.record.MybatisRecordProvider} The record provider parameter is MybatisRecordProvider
type.
* @see io.github.nichetoolkit.mybatis.record.MybatisRecordProvider
* @see org.springframework.beans.factory.annotation.Autowired
*/
@Autowired
public MybatisRecordAutoRegister(MybatisRecordProvider,?,?> recordProvider) {
this.recordProvider = recordProvider;
}
@Override
public void afterPropertiesSet() {
recordProvider.registerAsDefault();
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy