Change datasource configuration and remove driver class from properties.

This commit is contained in:
Konstantinos Triantafyllou 2024-11-01 13:51:14 +02:00
parent 5965836486
commit 91f512b1e2
4 changed files with 6 additions and 22 deletions

View File

@ -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();
}
}

View File

@ -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;
}

View File

@ -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<String, String> getProperties() {
Map<String, String> 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());

View File

@ -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.