Created
August 26, 2023 00:05
-
-
Save disc99/e641e772f2cccfb6ac7d17ef4dc2f987 to your computer and use it in GitHub Desktop.
Manual property configuration with Spring Boot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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