11package com .simon .config ;
22
3+ import com .alibaba .druid .pool .DruidDataSource ;
34import org .springframework .beans .factory .annotation .Autowired ;
45import org .springframework .context .annotation .Bean ;
56import org .springframework .context .annotation .Configuration ;
910
1011import javax .sql .DataSource ;
1112
13+
1214/**
1315 * Created by simon on 2017/2/20.
1416 */
@@ -18,12 +20,21 @@ public class DataSourceConfig {
1820 private Environment env ;
1921
2022 @ Bean
21- public DataSource dataSource () {
22- DriverManagerDataSource dataSource = new DriverManagerDataSource ();
23+ public DruidDataSource dataSource () {
24+ // DriverManagerDataSource dataSource = new DriverManagerDataSource();
25+ DruidDataSource dataSource = new DruidDataSource ();
2326 dataSource .setDriverClassName (env .getProperty ("spring.datasource.driver-class-name" ));
2427 dataSource .setUrl (env .getProperty ("spring.datasource.url" ));
2528 dataSource .setUsername (env .getProperty ("spring.datasource.username" ));
2629 dataSource .setPassword (env .getProperty ("spring.datasource.password" ));
30+ dataSource .setMaxActive (20 );
31+ dataSource .setInitialSize (1 );
32+ dataSource .setMaxWait (60000 );
33+ dataSource .setMinIdle (3 );
34+ dataSource .setRemoveAbandoned (true );
35+ dataSource .setRemoveAbandonedTimeout (180 );
36+ dataSource .setConnectionProperties ("clientEncoding=UTF-8" );
37+ dataSource .setTestWhileIdle (false );
2738 return dataSource ;
2839 }
2940
0 commit comments