From 91f512b1e22fed5d14d916fa7fbc2f9e1382a5c9 Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Fri, 1 Nov 2024 13:51:14 +0200 Subject: [PATCH] Change datasource configuration and remove driver class from properties. --- .../developers/configuration/DataSourceConfig.java | 11 +++++------ .../dnetlib/developers/configuration/Datasource.java | 9 --------- .../eu/dnetlib/developers/services/DeployService.java | 5 +---- src/main/resources/developers.properties | 3 --- 4 files changed, 6 insertions(+), 22 deletions(-) diff --git a/src/main/java/eu/dnetlib/developers/configuration/DataSourceConfig.java b/src/main/java/eu/dnetlib/developers/configuration/DataSourceConfig.java index f2dd1ac..333dd76 100644 --- a/src/main/java/eu/dnetlib/developers/configuration/DataSourceConfig.java +++ b/src/main/java/eu/dnetlib/developers/configuration/DataSourceConfig.java @@ -1,6 +1,7 @@ package eu.dnetlib.developers.configuration; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.datasource.DriverManagerDataSource; @@ -19,11 +20,9 @@ public class DataSourceConfig { @Bean public DataSource dataSource() { - DriverManagerDataSource dataSource = new DriverManagerDataSource(); - dataSource.setDriverClassName(this.datasource.getDriver()); - dataSource.setUrl(this.datasource.getUrl()); - dataSource.setUsername(this.datasource.getUsername()); - dataSource.setPassword(this.datasource.getPassword()); - return dataSource; + return DataSourceBuilder.create() + .url(this.datasource.getUrl()) + .username(this.datasource.getUsername()) + .password(this.datasource.getPassword()).build(); } } diff --git a/src/main/java/eu/dnetlib/developers/configuration/Datasource.java b/src/main/java/eu/dnetlib/developers/configuration/Datasource.java index ce1e6ce..1caa488 100644 --- a/src/main/java/eu/dnetlib/developers/configuration/Datasource.java +++ b/src/main/java/eu/dnetlib/developers/configuration/Datasource.java @@ -1,7 +1,6 @@ package eu.dnetlib.developers.configuration; public class Datasource { - private String driver; private String url; private String username; private String password; @@ -9,14 +8,6 @@ public class Datasource { public Datasource() { } - public String getDriver() { - return driver; - } - - public void setDriver(String driver) { - this.driver = driver; - } - public String getUrl() { return url; } diff --git a/src/main/java/eu/dnetlib/developers/services/DeployService.java b/src/main/java/eu/dnetlib/developers/services/DeployService.java index 6e03fe7..7601d27 100644 --- a/src/main/java/eu/dnetlib/developers/services/DeployService.java +++ b/src/main/java/eu/dnetlib/developers/services/DeployService.java @@ -22,9 +22,7 @@ public class DeployService { @PostConstruct public void checkProperties() { - if (properties.getDatasource().getDriver() == null || properties.getDatasource().getDriver().isEmpty()) { - throw new RuntimeException("developers.datasource.driver is missing!"); - } else if (properties.getDatasource().getUrl() == null || properties.getDatasource().getUrl().isEmpty()) { + if (properties.getDatasource().getUrl() == null || properties.getDatasource().getUrl().isEmpty()) { throw new RuntimeException("developers.datasource.url is missing!"); } else if (properties.getIssuer() == null || properties.getIssuer().isEmpty()) { throw new RuntimeException("developers.issuer is missing!"); @@ -33,7 +31,6 @@ public class DeployService { public Map getProperties() { Map response = new HashMap<>(); - response.put("developers.datasource.driver", properties.getDatasource().getDriver()); response.put("developers.datasource.url", properties.getDatasource().getUrl()); response.put("developers.datasource.username", properties.getDatasource().getUsername()); response.put("developers.datasource.password", properties.getDatasource().getPassword()); diff --git a/src/main/resources/developers.properties b/src/main/resources/developers.properties index c4bafe5..8dbf6f4 100644 --- a/src/main/resources/developers.properties +++ b/src/main/resources/developers.properties @@ -1,6 +1,3 @@ -developers.datasource.driver=org.postgresql.Driver -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect - ## API Documentation Properties api.title = Developers API api.description = Developers API includes authentication methods and provides functionalities to manage OpenAIRE Dynamic AAI APIs.