Spring Boot Dynamic Beans Example

You can create dynamic & configuration driven beans in Spring Boot in following way. Note: Below example full code is available at https://github.com/imran9m/spring-boot-dynamic-beans For the example, Let’s create dynamic RestClient beans with customized connection timeout and user-agent configuration to use anywhere we want. Let’s go with following configuration to manage customized properties for two dynamic RestClient beans. application.yml restClients: clients: - clientName: test1 connectionTimeout: 6000 responseTimeout: 6000 userAgent: test1 - clientName: test2 connectionTimeout: 5000 responseTimeout: 5000 userAgent: test2 Now, let’s load this configuration into custom configuration properties record....

January 2, 2025 · 4 min · Imran