1

Im not sure if this is possible. Im working with Azure services and I'm able to a create databases according to the info provided by the user in a front-end form. Im not able to determinate the jdbc url in the first execution of spring boot for that reason I've used the following line in the main java class:

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })

When the database exist i have the jdbc url string connection, but I don't know how to set that configuration and tell to jpa execute their task as create the tables according to the Entities in my project.

I found the following examples, but it depends on a existing datasource, but in the scenario exposed I don't have a database until the user fills a form and sends it:

@Bean
@Primary
public DataSource dataSource() {
    return DataSourceBuilder
        .create()
        .username("")
        .password("")
        .url("")
        .driverClassName("")
        .build();
}

the question is is there a way to provide a jdbcurl to spring boot jpa dynamically? Thanks for your help.

Basically I've tried to configure a HikariDataSource instance for myself like this, bit it doesn't works because the datasource in the first run is undefined and the app crashed because jpa needs a existing datasource:

@Configuration
public class DataSourceConfig {

    private HikariDataSource dataSource;

    public void updateDataSource(String url) {
        HikariConfig config = new HikariConfig();
        config.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        config.setJdbcUrl(url);
        dataSource = new HikariDataSource(config);
    }

    @Bean
    public HikariDataSource getDataSource() {
        return dataSource;
    }
}
Brayan Loayza
  • 678
  • 7
  • 15

0 Answers0