package com.demo.dao.utils;
import java.beans.PropertyVetoException;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.TransactionManagementConfigurer;
import com.mchange.v2.c3p0.ComboPooledDataSource;
/**
* 数据源工具类
*
* @author 熊佳佳
*
*/
@Configuration
@PropertySource("classpath:/application.properties")
public class DataSourceConfiguration{
@Autowired
private Environment props;
@Bean(name = "dataSource")
public ComboPooledDataSource dataSource() throws PropertyVetoException, SQLException {
ComboPooledDataSource dataSource = new ComboPooledDataSource();
dataSource.setDriverClass(props.getProperty("jdbc.driver"));
dataSource.setJdbcUrl(props.getProperty("jdbc.url"));
dataSource.setUser(props.getProperty("jdbc.username"));
dataSource.setPassword(props.getProperty("jdbc.password"));
dataSource.setMaxPoolSize(40);
dataSource.setMinPoolSize(2);
dataSource.setInitialPoolSize(10);
dataSource.setMaxStatements(20);
return dataSource;
}
}
数据源
最新推荐文章于 2024-01-22 14:20:04 发布