Configuration using annotation @SpringBootApplication

前端 未结 5 1844
挽巷
挽巷 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 18:51

    When setting up a Spring boot project, have your Application class (the one that contains the @SpringBootApplication annotation in the base package.

    One of the things the @SpringBootApplication does is a component scan. But, it only scans on sub-packages. i.e. if you put that class in com.mypackage, then it will scan for all classes in sub-packages i.e. com.mypackage.*.

    If you do not want to do it this way, you can also add a @ComponentScan to a class specifying the root package i.e @ComponentScan("com.mypackage")

    I would recommend you have a base package i.e com.mypackage. And within those packages, have your sub-packages. Have you class containing the @SpringBootApplication in that base package.

提交回复
热议问题