package cn.lihongjie.coal.spring.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.p6spy.engine.spy.P6DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;

import javax.sql.DataSource;

@Configuration
public class DruidConfig {

    @Autowired Environment environment;

    @ConfigurationProperties("spring.datasource.druid")
    @Bean
    public DataSource druidDataSource() {
        return new DruidDataSource();
    }

    @Bean
    @Primary
    @Profile({"dev", "master"})
    public DataSource p6DataSource() {

        return new P6DataSource(druidDataSource());
    }
}
