Configure DataSource programmatically in Spring Boot

You can use DataSourceBuilder if you are using jdbc starter. Also, in order to override the default autoconfiguration bean you need to mark your bean as a @Primary In my case I have properties starting with datasource.postgres prefix. E.g @ConfigurationProperties(prefix = “datasource.postgres”) @Bean @Primary public DataSource dataSource() { return DataSourceBuilder .create() .build(); } If it … Read more