matrix.boot.jdbc.config.BasicDataSourceAutoConfiguration Maven / Gradle / Ivy
The newest version!
package matrix.boot.jdbc.config;
import lombok.extern.slf4j.Slf4j;
import matrix.boot.jdbc.beans.MoreDataSource;
import matrix.boot.jdbc.properties.JdbcProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import javax.sql.DataSource;
/**
* 基础数据源自动装配
* @author wangcheng
* date 2021/8/16
*/
@EnableConfigurationProperties(JdbcProperties.class)
@ConditionalOnExpression("${matrix.jdbc.enabled} && '${matrix.jdbc.init-type}'.equals('Basic')")
@Slf4j
public class BasicDataSourceAutoConfiguration {
/**
* 主数据源
* @param moreDataSource 多数据源
* @return 数据源
*/
@Bean
public DataSource dataSource(MoreDataSource moreDataSource) {
log.info("BasicDataSource init success!");
return moreDataSource.getMasterDataSource();
}
}