1

I'm trying make datasource url configurable externally(fetching from a Restful service response), however I need to know if the other datasource properties still remain the same and is applied to the datasource bean

import javax.sql.DataSource;
.
.
@Configuration
public class DataSourceConfig(){

@Bean
public DataSource dataSource() {
  String userName = env.getRequiredProperty("spring.datasource.username");
  String password = env.getRequiredProperty("spring.datasource.password");
  String url = getTheJdbcUrlFromExternalServiceProvider();
  return DataSourceBuilder.create().url(url).username(userName).password(password).build();
  }
}

and the remaining datasource properties are configured in application.properties file

spring.datasource.tomcat.max-active=100
spring.datasource.tomcat.test-on-borrow=true
spring.datasource.tomcat.min-idle=2
spring.datasource.tomcat.test-while-idle=true
spring.datasource.tomcat.time-between-eviction-runs-millis=600000
spring.datasource.tomcat.min-evictable-idle-time-millis=60000
spring.datasource.tomcat.validation-query=select 1 from dual

Does the spring datasource configuration properties gets applied to the datasource bean created and how to validate the same ? If not, how to externally configure the DB url?

technoJ
  • 175
  • 1
  • 1
  • 16

0 Answers0