com.jingshouyan.config.AppConfig Maven / Gradle / Ivy
package com.jingshouyan.config;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import javax.sql.DataSource;
/**
* @author jingshouyan
* 11/29/18 5:29 PM
*/
//@Configuration
public class AppConfig {
public static final String URL = "jdbc:mysql://127.0.0.1:3306/DB_TEST_S?useUnicode=true&characterEncoding=utf8&useSSL=false";
public static final String USERNAME = "root";
public static final String PASSWORD = "abcd1234";
public static final String DRIVER = "com.mysql.jdbc.Driver";
@Bean
public NamedParameterJdbcTemplate namedParameterJdbcTemplate(DataSource dataSource) {
return new NamedParameterJdbcTemplate(dataSource);
}
@Bean
DataSource dataSource() {
return initDataSource();
}
private DataSource initDataSource() {
HikariConfig config = new HikariConfig();
config.setJdbcUrl(URL);
config.setDriverClassName(DRIVER);
config.setUsername(USERNAME);
config.setPassword(PASSWORD);
config.setMaximumPoolSize(20);
config.setMinimumIdle(5);
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
HikariDataSource dataSource = new HikariDataSource(config);
return dataSource;
}
}