multi module component scanning not working in spring boot

后端 未结 1 1801
孤独总比滥情好
孤独总比滥情好 2021-02-19 19:49

I am having two module web and business. I have included business in the web. But when I try to include a service interface from business into web using @autowired,

相关标签:
1条回答
  • 2021-02-19 20:00

    @SpringBootApplication only scans the packages of the class with the annotation itself and all packages below.

    Example: If the class with the SpringBootApplication annotation is in the package com.project.web, then this packages and all below that are scanned.

    However, if you have your services in the package com.project.business, the beans won't be scanned.

    In that case you have to add the annotation @ComponentScan() to your application class, and add all packages you want to scan as value in that annotation, e.g. @ComponentScan({"com.project.web", "com.project.business"}).

    0 讨论(0)
提交回复
热议问题