Spring Boot API with Multiple Controllers?

后端 未结 8 1068
孤城傲影
孤城傲影 2021-02-07 12:36

I am starting to learn Spring Boot. I am struggling to find an example with multiple RestControllers, which indicates to me that I may be doing something wrong. I am trying a ve

8条回答
  •  一生所求
    2021-02-07 13:04

    For Spring-boot 1.3.x and up, passing a base package to SpringBootApplication should work:

    @SpringBootApplication(scanBasePackages = {"com.demo"})
    public class DemoBootApplication {
        // code
    }
    

    This worked for me on a similar application using spring-boot 1.4.0. For earlier versions of spring-boot, it appears you'll have forego using SpringBootApplication and instead use the following to get same effect as above:

    @Configuration
    @EnableAutoConfiguration
    @ComponentScan(basePackages = {"com.demo"})
    public class DemoBootApplication {
        // code
    }
    

    I found this in the comments on this blog post.

提交回复
热议问题