Where to put @Bean in Spring Boot?

前端 未结 6 431
清歌不尽
清歌不尽 2020-12-24 05:32

I am wondering what the best place would be for a Spring Boot app to register additional beans. I have a Main class that is annotated with @SpringBootApplication

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-24 05:52

    It depends on personal choices and there is no good or bad way to do it. As it is preferred or showed way in documentation of Spring Boot references.

    As annotating main class with @SpringBootApplication makes it convenient to Bootstrap spring app. But it does only looks for subpackages so nesting configuration inside subfolder would not detect the @Bean automatically that is the only thing to remember other than it's all about personal preferences.

提交回复
热议问题