Hi,
I have a requirement that, i need to create a datasource in the spring boot application to make a DB operations.
Currently i am using JpaRepository to do this using the dataSource created programmatically with @Configuration annotated class.
HikariDataSource dataSource = new HikariDataSource();
dataSource.setJdbcUrl("<url with the host name, port and database>");
dataSource.setUsername("userName");
dataSource.setPassword("xxxxxx");
dataSource.setDriverClassName("org.postgresql.Driver"); // Set the PostgreSQL driver class explicitly
dataSource.setMaximumPoolSize(1);
dataSource.setMinimumIdle(5);
return dataSource;`
While application startup, the datasource is configured and working fine.
But my requirement in the real timeis, The datasource properties(DB name, usename, password etc) are not available in the application startUp, when ever any one of the end point is triggered from the rest controller, based on one mandatory header, i will make an one service call to get the db details and need to create a datasource for first time and cached for further usage.
For Spring boot in the internet every whare it is suggested that to configure the data source in application start up with @Configuration annotation only.
Can any one help on my requirement to achieve this?
Thanks in advance
Comment From: philwebb
Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.