|
10 | 10 |
|
11 | 11 | package org.dpppt.backend.sdk.ws.config;
|
12 | 12 |
|
| 13 | +import java.util.Map; |
13 | 14 | import javax.sql.DataSource;
|
14 | 15 | import org.dpppt.backend.sdk.ws.security.KeyVault;
|
15 | 16 | import org.dpppt.backend.sdk.ws.security.KeyVault.PrivateKeyNoSuitableEncodingFoundException;
|
16 | 17 | import org.dpppt.backend.sdk.ws.security.KeyVault.PublicKeyNoSuitableEncodingFoundException;
|
17 | 18 | import org.flywaydb.core.Flyway;
|
18 |
| -import org.springframework.beans.factory.annotation.Autowired; |
19 | 19 | import org.springframework.beans.factory.annotation.Value;
|
| 20 | +import org.springframework.cloud.CloudFactory; |
| 21 | +import org.springframework.cloud.service.PooledServiceConnectorConfig.PoolConfig; |
| 22 | +import org.springframework.cloud.service.relational.DataSourceConfig; |
20 | 23 | import org.springframework.context.annotation.Bean;
|
21 | 24 | import org.springframework.context.annotation.Configuration;
|
22 |
| -import org.springframework.context.annotation.Lazy; |
23 | 25 |
|
24 | 26 | @Configuration
|
25 | 27 | public abstract class WSCloudBaseConfig extends WSBaseConfig {
|
26 | 28 |
|
27 |
| - @Autowired @Lazy private DataSource dataSource; |
28 |
| - |
29 | 29 | abstract String getPublicKey();
|
30 | 30 |
|
31 | 31 | abstract String getPrivateKey();
|
32 | 32 |
|
33 | 33 | @Value("${ws.cloud.base.config.publicKey.fromCertificate:true}")
|
34 | 34 | private boolean publicKeyFromCertificate;
|
35 | 35 |
|
| 36 | + @Value("${datasource.maximumPoolSize:5}") |
| 37 | + int dataSourceMaximumPoolSize; |
| 38 | + |
| 39 | + @Value("${datasource.connectionTimeout:30000}") |
| 40 | + int dataSourceConnectionTimeout; |
| 41 | + |
| 42 | + @Value("${datasource.leakDetectionThreshold:0}") |
| 43 | + int dataSourceLeakDetectionThreshold; |
| 44 | + |
| 45 | + @Bean |
36 | 46 | @Override
|
37 | 47 | public DataSource dataSource() {
|
38 |
| - return dataSource; |
| 48 | + PoolConfig poolConfig = new PoolConfig(dataSourceMaximumPoolSize, dataSourceConnectionTimeout); |
| 49 | + DataSourceConfig dbConfig = |
| 50 | + new DataSourceConfig( |
| 51 | + poolConfig, |
| 52 | + null, |
| 53 | + null, |
| 54 | + Map.of("leakDetectionThreshold", dataSourceLeakDetectionThreshold)); |
| 55 | + CloudFactory factory = new CloudFactory(); |
| 56 | + return factory.getCloud().getSingletonServiceConnector(DataSource.class, dbConfig); |
39 | 57 | }
|
40 | 58 |
|
41 | 59 | @Bean
|
|
0 commit comments