How to configure a datasource programmatically
See original GitHub issueI’d like to know how can I configure a datasource programmatically withtout using application.properties
.
Spring Boot way:
@Configuration
public class KubDataSourceConfig {
@Bean
public DataSource getDataSource() {
Map<String, String> credentials = getCredentials();
return DataSourceBuilder.create()
.url(credentials.get("url"))
.username(credentials.get("username"))
.password(credentials.get("password"))
.build();
}
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:8
- Comments:6
Top Results From Across the Web
Configuring a DataSource Programmatically in Spring Boot
Learn how to configure a Spring Boot DataSource programmatically, thereby side-stepping Spring Boot's automatic DataSource configuration ...
Read more >Configure DataSource programmatically in Spring Boot
In my case I have properties starting with datasource.postgres prefix. E.g @ConfigurationProperties(prefix = "datasource.postgres") @Bean @ ...
Read more >How to configure a Datasource programmatically
This article covers how to define a Datasource resource programmatically using the DataSourceDefinition annotation. Then, we will show to to ...
Read more >Spring Boot DataSource Configuration - HowToDoInJava
2. Configuring a DataSource ... Spring boot allows defining datasource configuration in following ways: ... During application startup, the ...
Read more >Java DataSource, JDBC DataSource Example - DigitalOcean
Make sure that above configurations match with your local setup. Also make sure you have MySQL and Oracle DB JDBC jars included in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You can also use an
AgroalPropertiesReader
While there isn’t a way to do this similar to Spring Boot, you can achieve that with this workaround.
Create a class that implements javax.sql.DataSource, just like below:
` @ApplicationScoped public class CustomDataSource extends OracleDataSource {
} `