By default, spring beans are single. I am wondering if there is a way to get multiple instances of the same bean for processing.
Here is what i am doing now
@Configuration
public class ApplicationMain {
@Value("${service.num: not configured}")
private int num;
@PostConstruct
public void run(){
for (int i = 0; i < num ; i++) {
MyService ser = new MyService(i);
Future<?> tasks = executor.submit(ser);
}
}
}
Here is a class of service
public class MyService implements Runnable {
private String name;
public Myservice(int i){
name=String.ValueOf(i);
}
}
I have simplified my business here. I want to have MyService as spring bean and get as much as possible based on configuartion (which is num) in the above for-loop? I wonder how this is possible.
thank
source
share