Field XXX in XXXX required a bean of type XXXX that could not be found

这个报错的意思是:没有找到相应的bean。

出现这个情况我遇到了两种:

1.spring没有扫描到相应的bean。

原因是springboot项目启动,只有@SpringBootApplication 所在的包被被扫描,如果有其他需要扫描的包,需要显式写明:

@SpringBootApplication
@MapperScan({"cn.jhxcom.web.demo.mapper",
    "com.baomidou.mybatisplus.samples.quickstart.mapper",
    "cn.jhxcom.project.system.user.mapper",
    })
public class HaoWebDemoApplication {...}

这样就可以扫描到了。

但是需要扫描的包很多的话,这样的方式显然不好,所以最好的方式是把@SpringBootApplication 所在类放在其他包的上层。

2.加相应的注释。在注入的时候报这个错误,应该是被注入的对象类上没有如:@Service 的注解。

原文地址:https://www.cnblogs.com/zhangxj/p/9860462.html

时间: 2024-10-10 20:28:19

Field XXX in XXXX required a bean of type XXXX that could not be found的相关文章

运行springboot项目报错:Field userMapper in XX required a bean of type 'xx' that could not be found.

运行springboot项目报错: *************************** APPLICATION FAILED TO START *************************** Description: Field userMapper in com.whohim.springboot.service.impl.UserServiceImpl required a bean of type 'com.whohim.springboot.dao.UserMapper' t

SpringBoot: Field xxx in xxx required a bean of type 'xxx' that could not be found.

SpringBoot自动注入报了如下错误 . 原因是我这个模块依赖另一个模块里面的被Spring管理的类,但是不在同一包下面, 并且启动类不是在根包下面,所以就导致了springboot启动的时候扫描不到,也就管理不到这个类,也就无法找到, 解决方案: 1.SpringBoot启动类放到包的跟包下面比如每个包都包含 cn.arebirth.xx  那就放在cn.arbeirth下面 2.设置SpringBoot扫描的包路径即可解决 SpringBoot: Field xxx in xxx req

Sping Cloud项目启动报A component required a bean of type 'com.tianyan.bbc.dao.SecurityUserBaseMapper' that could not be found.

项目构建正常,启动和Debug报以下错误: Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.2018-12-14 09:49:32.038 [main] ERROR o.s.b.diagnostics.LoggingFailureAnalysisReporter - ***************************

Parameter 0 of method 方法b in 类a required a bean of type ***

Description: Parameter 0 of method getLastTick in com.td.spec.marketdata.stockdatasourceserver.service.CacheProcessor required a bean of type 'com.td.spec.marketdata.common.entity.StockTick' that could not be found. Action: Consider defining a bean o

springboot 报错Field XXX required a bean of type XXX that could not be found.

报错原因: MyBatis是第三方组件,spring并不会自动管理MyBatis相关对象的生命周期,因此需要手动配置,将MyBatis相关对象交给spring容器来管理. 解决方式: 在启动类中增加注解@MapperScan("cn.lxy.repository") 原文地址:https://www.cnblogs.com/think-world/p/12300546.html

springboot 工程启动报错之Consider defining a bean of type ‘XXX’ in your configuration.

一.前言: 使用springboot自动注入的方式搭建好了工程,结果启动的时候报错了!!!,错误如下图: Description: Field userEntityMapper in com.xxx.xxx.service.UserService required a bean of type 'com.xxx.xxx.dao.UserEntityMapper' that could not be found. Action: Consider defining a bean of type '

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

问题描述 org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'xxxxx.UserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factor

Consider defining a bean of type `xxx` in your configuration问题解决问题解决

在使用SpringBoot装配mybatis时出现了异常 *************************** APPLICATION FAILED TO START *************************** Description: Field studentService in com.example.demo.action.StudentController required a bean of type 'com.example.demo.service.StudentS

【spring boot】mybatis启动报错:Consider defining a bean of type 'com.newhope.interview.dao.UserMapper' in your configuration.

启动报错: 2018-02-24 22:41:00.442 WARN 2952 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error c