2

Always when i connect to my database, I see 10 idle connection. How can I set this in application.yml.

I use spring boot 1.5.6.RELEASE.

It's not working:

spring:
   datasource:
    maxActive: 5
    maxIdle: 5
    minIdle: 5
    initialSize: 5

When I created @Bean it's working, but I need solution in application.yml

@Configuration
public class DBConfig {

    @Value("${dbconfig.driver-class-name}")
    private String driverClassName;
    @Value("${dbconfig.url}")
    private String url;
    @Value("${dbconfig.username}")
    private String username;
    @Value("${dbconfig.password}")
    private String password;

    @Bean
    public DataSource dataSource() throws SQLException {
        BasicDataSource ds = new BasicDataSource();
        ds.setDriverClassName(driverClassName);
        ds.setUrl(url);
        ds.setUsername(username);
        ds.setPassword(password);
        return ds;
    }
Stack Over
  • 287
  • 2
  • 4
  • 14

1 Answers1

3

I think you're missing to say these are properties. I think the following will work.

spring:
    dataSource:
            properties:
                 maxActive: 5 
                 maxIdle: 5 
                 minIdle: 5 
                 initialSize: 5

Note: If you're using tomcat-jdbc, you have to define it explicitly like,

spring:
    dataSource:
        tomcat:
             max-active: 5 
             max-idle: 5 
             min-idle: 5 
             initial-size: 5
Sridhar
  • 1,518
  • 14
  • 27