I have a class similar to the following:
@Configuration public class ApplicationConfiguration { private <T> T createService(Class<T> serviceInterface) { // implementation omitted } @Bean public FooService fooService() { return createService(FooService.class); } @Bean public BarService barService() { return createService(BarService.class); } ... }
The problem is that there are too many @Bean -annotated methods that differ only in their names, return types and arguments for calling the crateService method. I would like to make this class look like the following:
@Configuration public class ApplicationConfiguration { private static final Class<?>[] SERVICE_INTERFACES = { FooSerivce.class, BarService.class, ...}; private <T> T createService(Class<T> serviceInterface) {
Is this possible in Spring?
source share