Skip to content

Instantly share code, notes, and snippets.

@disc99
Created August 26, 2023 00:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save disc99/e641e772f2cccfb6ac7d17ef4dc2f987 to your computer and use it in GitHub Desktop.
Save disc99/e641e772f2cccfb6ac7d17ef4dc2f987 to your computer and use it in GitHub Desktop.
Manual property configuration with Spring Boot
@Configuration
class Config {
@Bean(name = "myDataSource")
DataSource myDataSource(DataSourceProperties dataSourceProperties, ConfigurableEnvironment environment) {
MutablePropertySources propertySources = environment.getPropertySources();
Binder binder = new Binder(ConfigurationPropertySources.from(propertySources));
HikariDataSource dataSource = dataSourceProperties.initializeDataSourceBuilder().type(HikariDataSource.class).build();
BindResult<HikariDataSource> result = binder.bind("my.spring.datasource.hikari", Bindable.ofInstance(dataSource));
return result.get();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment