I am converting a Spring legacy application based on XML to Spring Boot with java based configuration. My question is, is it possible to instantiate same bean class with different bean names? Example:
@Configuration
public class HelloWorldConfig {
@Bean
public HelloWorld helloWorld(){
return new HelloWorld();
}
}
Can I have Spring boot instantiate above helloWorld bean using dynamically generated names like helloWorld_1, helloWorld_2 etc in a loop? I want to control the naming of these beans. _1, _2 is something I will provide and these actually are IP Addresses. All these beans are instances of same class HelloWorld. Here is more context to what I am asking. I am performing a distributed transactions on several data sources. These data sources can be anywhere from 2 to N. Now, I need to instantiate session factories, transaction managers and Dao impl classes one for each of these data sources. This is my usecase. I am not building a web application, but a console application. Just to be clear. Really appreciate, if there is a way out for this problem.