0

I have a Spring Boot 1.5 app which is configured with an application.yml file. I need to manage the connection pool which is default - Tomcat.

The problem is that the application.yml has a datasources property for several datasources. My global datasource.max-active=10 (UPDATE: datasource.tomcat.max-active=10 is ignored too) is being completely ignored (I created a test to see what datasource is being injected, and default maxActive in them is set to 100). I have to add it to every datasource separately to make the pool work the way I need it to.

The application.yml looks like this (this is only part of it), and it creates datasource with maxActive=10, but there is bunch of repetitions:

spring:
  .... #bunch of stuff, deleted for simplicity
  datasource: #Added by me, ignored by Spring
    max-active: 10 #Added by me, ignored by Spring
datasources:
  datasource1:
    url: jdbc:mysql://url:port1
    max-active: 10 #Added by me, works
  datasource2:
    url: jdbc:mysql://url:port2
    max-active: 10 #Added by me, works

Question: what is the correct way to set the max-active property globally to avoid this repetition? Thanks.

Battle_Slug
  • 2,055
  • 1
  • 34
  • 60

1 Answers1

3

When you are using multiple data sources, spring boot does not provide a default data source auto-configuration. This also means you have to provide connection pool properties for each data source. I don't think it's possible to set it globally. Instead, you can use the placeholder to set it once and use it everywhere.

custom:
 max-active: 10 
spring:
datasources:
  datasource1:
    url: jdbc:mysql://url:port1
    max-active: ${custom.max-active}
  datasource2:
    url: jdbc:mysql://url:port2
    max-active: ${custom.max-active}

You can find more info here: How to setup multiple connection pools when multiple datasources are used in Spring Boot?

Mohit Singh
  • 496
  • 2
  • 11