I want to create multiple beans based upon the value in configuration file. I have the bean ready in configuration file. But how can I create multiple beans.
My current configuration file.
@Configuration
public class JMSConfig {
@Bean
public DefaultMessageListenerContainer listenerContainers() {
...
}
}
My idea to achieve the requirement. If I use prototype scope I will get a new bean each time I ask for that bean. So I added prototype.
@Configuration
public class JMSConfig{
@Value("${value}")
private long value;
@Bean
@Scope("prototype")
public DefaultMessageListenerContainer listenerContainers() {
.....
}
for(i = 0; i < value; i++){
//get a new bean
}
}
The important challenge I am facing is
- How to get a new bean(the part I commented)
- How can I trigger the 'for' loop as I start the application Do I need to do this part in another class or how can I achieve this requirement?