spring boot 多个包启动失败-添加多个包扫描

当Spring Boot项目组织成多个子包时,启动可能会遇到bean初始化失败的问题。通过在启动类中指定扫描的包路径可以解决此问题,如`@ComponentScan(basePackages = {"com.xxx.xx", "com.xxx.yy"})`。然而,这可能导致新添加的mapper实例化失败,报出异常。为解决这个问题,可以在启动类中使用`@MapperScan`注解并指定多个包,如`@MapperScan({"com.xxx.xx.mapper", "com.xxx.yy.mapper"})`。" 84556740,7526502,深度解析Faster R-CNN:从输入到输出的全程剖析,"['计算机视觉', '深度学习', '目标检测', '卷积网络', 'Faster R-CNN']
摘要由CSDN通过智能技术生成

spring boot 多个包启动失败-添加多个包扫描

表现:启动时提示如下信息:
因为项目需要,将代码结构调整为:

  • com.xxx
    • xx
    • yy
    • XxxxApplication

这种组织结构,注意,此处时同一个项目(没有拆分成多个maven模块),有多个包保存不同功能模块的代码。此时启动项目,报错如下:

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2019-11-12 19:28:40.563 [recruit_system] [main] ERROR [org.springframework.boot.SpringApplication] -Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeForPcController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'enrollInfoServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.xxx.yy.mapper.EnrollInfoMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:321)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
	at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
	at org.springframework.boot
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值