[email protected]、@Component、@Service、@Controller、@Mapper、@Repository And other annotation injected classes , Pac...">

当前位置:网站首页>Unable to use the bean introduced into the jar package

Unable to use the bean introduced into the jar package

2022-06-24 22:29:00 follow_ me!

problem :

stay A Project use @[email protected]、@Component、@Service、@Controller、@Mapper、@Repository And other annotation injected classes , Pack it up jar After the introduction of B The project cannot be used @Autowired Automatic injection

Analytical problem :

because SpringBoot The default path for automatic scanning is the package where the main startup class is located and its child packages , If jar In bag bean The path to is not included , Will not be scanned , So it can't be used @Autowired Automatic injection

resolvent :

resolvent 1:
@SpringBootApplication Set parameters :scanBasePackages={“com."}
 Insert picture description here
resolvent 2: Add... On the main boot :@ComponentScan("com.
”)
 Insert picture description here

原网站

版权声明
本文为[follow_ me!]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202211236393281.html