Configuration using annotation @SpringBootApplication

前端 未结 5 1837
挽巷
挽巷 2020-11-27 18:15

I have problem with Spring Boot configuration.

I have created base Spring Boot project using https://start.spring.io/

And I have a problem, configuration wor

5条回答
  •  被撕碎了的回忆
    2020-11-27 19:00

    The Spring Boot documentation for @SpringBootApplication states

    Many Spring Boot developers always have their main class annotated with @Configuration, @EnableAutoConfiguration and @ComponentScan. Since these annotations are so frequently used together (especially if you follow the best practices above), Spring Boot provides a convenient @SpringBootApplication alternative.

    The @SpringBootApplication annotation is equivalent to using @Configuration, @EnableAutoConfiguration and @ComponentScan with their default attributes: [...]

    where the @ComponentScan javadoc states

    If specific packages are not defined, scanning will occur from the package of the class that declares this annotation.

    That is, only the types that are in the same package as your ReadingListApplication will be scanned.

    If you want a custom configuration, provide your own @Configuration, @EnableAutoConfiguration, and @ComponentScan, as appropriate.

提交回复
热议问题