From 973f8938dd0554560dfc86d7410ebfb3683d148d Mon Sep 17 00:00:00 2001 From: Felix Haller Date: Fri, 21 May 2021 13:06:52 +0200 Subject: [PATCH] fix interops datasource cloud config --- .../dpppt-backend-sdk-interops/pom.xml | 6 +++++ .../interops/config/WSCloudBaseConfig.java | 27 ++++++++++++++++--- .../dpppt-backend-sdk-ws/pom.xml | 2 +- dpppt-backend-sdk/pom.xml | 1 + 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/dpppt-backend-sdk/dpppt-backend-sdk-interops/pom.xml b/dpppt-backend-sdk/dpppt-backend-sdk-interops/pom.xml index cf933d533..66188f022 100644 --- a/dpppt-backend-sdk/dpppt-backend-sdk-interops/pom.xml +++ b/dpppt-backend-sdk/dpppt-backend-sdk-interops/pom.xml @@ -71,6 +71,12 @@ spring-security-web + + org.springframework.boot + spring-boot-starter-cloud-connectors + ${spring-cloud-connectors-version} + + org.springframework.boot diff --git a/dpppt-backend-sdk/dpppt-backend-sdk-interops/src/main/java/org/dpppt/backend/sdk/interops/config/WSCloudBaseConfig.java b/dpppt-backend-sdk/dpppt-backend-sdk-interops/src/main/java/org/dpppt/backend/sdk/interops/config/WSCloudBaseConfig.java index 69f3b6474..4e813de7b 100644 --- a/dpppt-backend-sdk/dpppt-backend-sdk-interops/src/main/java/org/dpppt/backend/sdk/interops/config/WSCloudBaseConfig.java +++ b/dpppt-backend-sdk/dpppt-backend-sdk-interops/src/main/java/org/dpppt/backend/sdk/interops/config/WSCloudBaseConfig.java @@ -10,21 +10,40 @@ package org.dpppt.backend.sdk.interops.config; +import java.util.Map; import javax.sql.DataSource; import org.flywaydb.core.Flyway; -import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.cloud.CloudFactory; +import org.springframework.cloud.service.PooledServiceConnectorConfig.PoolConfig; +import org.springframework.cloud.service.relational.DataSourceConfig; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Lazy; @Configuration public abstract class WSCloudBaseConfig extends WSBaseConfig { - @Autowired @Lazy private DataSource dataSource; + @Value("${datasource.maximumPoolSize:5}") + int dataSourceMaximumPoolSize; + @Value("${datasource.connectionTimeout:30000}") + int dataSourceConnectionTimeout; + + @Value("${datasource.leakDetectionThreshold:0}") + int dataSourceLeakDetectionThreshold; + + @Bean @Override public DataSource dataSource() { - return dataSource; + PoolConfig poolConfig = new PoolConfig(dataSourceMaximumPoolSize, dataSourceConnectionTimeout); + DataSourceConfig dbConfig = + new DataSourceConfig( + poolConfig, + null, + null, + Map.of("leakDetectionThreshold", dataSourceLeakDetectionThreshold)); + CloudFactory factory = new CloudFactory(); + return factory.getCloud().getSingletonServiceConnector(DataSource.class, dbConfig); } @Bean diff --git a/dpppt-backend-sdk/dpppt-backend-sdk-ws/pom.xml b/dpppt-backend-sdk/dpppt-backend-sdk-ws/pom.xml index 576be64de..3562cf66d 100644 --- a/dpppt-backend-sdk/dpppt-backend-sdk-ws/pom.xml +++ b/dpppt-backend-sdk/dpppt-backend-sdk-ws/pom.xml @@ -35,7 +35,7 @@ org.springframework.boot spring-boot-starter-cloud-connectors - 2.0.7.RELEASE + ${spring-cloud-connectors-version} diff --git a/dpppt-backend-sdk/pom.xml b/dpppt-backend-sdk/pom.xml index 839d2cbb2..b472dd9d3 100644 --- a/dpppt-backend-sdk/pom.xml +++ b/dpppt-backend-sdk/pom.xml @@ -27,6 +27,7 @@ 3.12.1 2.4.5 1.15.2 + 2.0.7.RELEASE