0

I create services bean in appconfig file. How create this beans with FactoryBean or other way to don't create it one by one?

@SpringBootApplication(exclude = {SecurityAutoConfiguration.class })
@ComponentScan
public class Application {
    public static void main(String[] args) {

        SpringApplication.run(Application.class, args);
    }

    @Bean
    public SimpleService<Work> workService() { return new SimpleServiceImpl<Work>() { }; }

    @Bean
    public SimpleService<User> userService() { return new SimpleServiceImpl<User>() { }; }

    @Bean
    public SimpleService<Author> authorService() { return new SimpleServiceImpl<Author>() { }; }

    @Bean
    public SimpleService<Genre> genreService() { return new SimpleServiceImpl<Genre>() { }; }

    @Bean
    public SimpleService<BookCondition> bookConditionService() { return new SimpleServiceImpl<BookCondition>() { }; }

    @Bean
    public SimpleService<BookType> bookTypeService() { return new SimpleServiceImpl<BookType>() { }; }

    @Bean
    public SimpleService<Offer> offerService() { return new SimpleServiceImpl<Offer>() { }; }

Except this services I have only genericService and genericsSrviseImpl.

1 Answers1

0

You can use @Service annotation.

Let's say your service/class name is SimpleServiceImpl then define @Service("SimpleService") on top of the class name. Spring will create this as a bean.

Another way to do that is using factoryBean which is explained in this link How to get beans created by FactoryBean spring managed?

Community
  • 1
  • 1
Bhavesh
  • 882
  • 2
  • 9
  • 18