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.SpringApplication.run(Spri

当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']
最低0.47元/天 解锁文章
604

被折叠的 条评论
为什么被折叠?



