package cn.wise.sc.energy.power.plant.business.config;


import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

/**
 * @ClassNameJdbcConfig
 * @Description 数据配置
 * 按需注入Bean对象
 * @Author qh
 * @Date2020/3/5 16:27
 * @Version V1.0
 **/
@Configuration
public class JdbcConfig {

    /**
     * 默认的数据库连接池
     * @return
     */
    @Bean(name = "dataSourceToken")
    @ConditionalOnMissingBean(DataSource.class)
    public DataSource createDataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://39.105.38.125:3306/turbinedb?useUnicode=true&characterEncoding=UTF-8&useSSL=false");
        dataSource.setUsername("root");
        dataSource.setPassword("Qzh-1234");
        return dataSource;
    }


    /**
     * jdbcTemplate 注册
     * @param dataSourceToken
     * @return
     */
    @Bean(name = "jdbcTemplate")
    public JdbcTemplate createJdbcTemplate(DataSource dataSourceToken) {
        return new JdbcTemplate(dataSourceToken);
    }
}