package com.xxx.base.springframework.db.config;

import com.alibaba.druid.pool.DruidDataSource;

import com.xxx.base.springframework.db.propertiesv.DruidProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @description: 单数据源配置
 * @author: huzhiwen
 * @create: 2020-11-16 17:56
 **/

@Configuration
@EnableTransactionManagement(proxyTargetClass = true)
public class SingleDataSource {
    /**
     * druid配置
     */
    @Bean
    @ConfigurationProperties(prefix = "spring.datasource")
    public DruidProperties druidProperties() {
        return new DruidProperties();
    }

    /**
     * 单数据源连接池配置
     */
    @Bean
    public DruidDataSource dataSource(DruidProperties druidProperties) {
        DruidDataSource dataSource = new DruidDataSource();
        druidProperties.config(dataSource);
        return dataSource;
    }
}