How to solve the error "Field service in com.xx.xxx.xxxx required a bean of type 'com.aa.bb.cc' that could not be found."
When runung a SpringBoot demo, I got a error as following:
*************************** APPLICATION FAILED TO START *************************** Description: Field service in com.hy.empcloud.EmpControl required a bean of type 'com.hy.empcloud.EmpService' that could not be found. The injection point has the following annotations: - @org.springframework.beans.factory.annotation.Autowired(required=true) Action: Consider defining a bean of type 'com.hy.empcloud.EmpService' in your configuration.
After I add a annotation "@Service" to the class com.hy.empCloud.EmpService, the error was solved.
package com.hy.empcloud;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Service;
// To provide service of employees
@Service
public class EmpService {
private List<Emp> emps;
public EmpService(){
emps=new ArrayList<Emp>();
emps.add(new Emp(1,"Andy",41));
emps.add(new Emp(2,"刘德华",42));
emps.add(new Emp(3,"Bill",43));
emps.add(new Emp(4,"比尔",44));
}
public List<Emp> getAll(){
return emps;
}
public Emp find(long id) throws Exception{
for(Emp e:emps) {
if(e.getId()==id) {
return e;
}
}
throw new Exception("No such employee whose's id="+id);
}
}
Here is the demo.
--END--
2019年8月24日14点24分
How to solve the error "Field service in com.xx.xxx.xxxx required a bean of type 'com.aa.bb.cc' that could not be found."的更多相关文章
- Field userService in com.wuji.controller.UserController required a bean of type 'com.wuji.service.UserService' that could not be found
Field userService in com.wuji.controller.UserController required a bean of type 'com.wuji.service.Us ...
- 解决办法 Field userService in com.sxsj.controller.RegistLoginController required a bean of type
转自:https://blog.csdn.net/awmw74520/article/details/82687288 APPLICATION FAILED TO START Error starti ...
- Visual Studio 2022 git error Unable to negotiate with xx.xxx.xxxx port 22: no matching host key type found. Their offer: ssh-rsa
前言 前两天因为升级了Git导致git提交拉取的时候都提示下面这个异常,然后经过一番折腾以后终于把这个问题解决了.但是今天我升级了下Visual Studio 2022将其升级到了17.1.3版本然后 ...
- 2. springboot启动报错:Field userMapper in com.service.UserService required a bean of type 'com.dao.UserMapper' that could not be found.
报错信息: 2018-06-25 14:26:17.103 WARN 49752 --- [ restartedMain] ationConfigEmbeddedWebApplicationCon ...
- 解决:Field xxMapper in xx.service.impl.xxServiceImpl required a bean of type 'xx.mapper.xxMapper'
1.启动 SpringBoot项目报错,使用的是Springboot.Spring.Mybatis连接Mysql数据库,启动SpringBoot项目报错,错误如下所示: _____ .__/\ .__ ...
- Spring Cloud Ribbon负载均衡配置类放在Spring boot主类同级增加Exclude过滤后报Field config in com.cloud.web.controller.RibbonConfiguration required a bean of type 'com.netflix.client.config.IClientConfig' that could not b
环境: Spring Cloud:Finchley.M8 Spring Boot:2.0.0.RELEASE 目录结构: 可以看到代码第13行的注释,我已经在@ComponentScan注解中添加了E ...
- springboot jpa mongodb 整合mysql Field in required a bean of type that could not be found Failed to load ApplicationContext
1.完整报错 *************************** APPLICATION FAILED TO START *************************** Descripti ...
- maven多模块启动required a bean of type com.xxx.xxx.service that could not be found.
Description: Field testService in com.xxx.xxx.api.controller.TestController required a bean of type ...
- 运行springboot项目报错:Field userMapper in XX required a bean of type 'xx' that could not be found.
运行springboot项目报错: *************************** APPLICATION FAILED TO START ************************** ...
随机推荐
- openlayers之全屏控件的使用
import { FullScreen } from 'ol/control' map.addControl(new FullScreen())
- 一头扎进 JAVA
硅不可 吉米 JAVA 基础 -- 基础不牢,地动山摇 子类应该比 父类更为 开放 (public protected default private) 子类方法不能比父类抛出更高异常( 可以为父类方 ...
- SQL SERVER 中 sp_rename 用法
转自:http://www.cnblogs.com/no7dw/archive/2010/03/04/1678287.html 因需求变更要改表的列名,平常都是跑到Enterprise manager ...
- Java构造二叉树、树形结构先序遍历、中序遍历、后序遍历
package com.example.demo; public class BTree { public int data; public BTree left; public BTree rigt ...
- C语言之在头文件中定义全局变量
通常情况下,都是在C文件中定义全局变量,在头文件中声明,但是,如果我们定义的全局变量需要被很多的C文件使用的话,那么将全局变量定义在头文件里面会方便很多,那到底是如何实现的? os_var.c文件内容 ...
- win 10.0.17134.915 版本无法更新处理方法
用CMD(以管理员方式运行)分别运行:1. Dism /Online /Cleanup-Image /RestoreHealth2. sfc /scannow 注意:第2步比较慢,有进度条,请耐心 ...
- 【BZOJ3143】【Luogu P3232】 [HNOI2013]游走 概率期望,图论
期望\(DP\)入门题目. 关键思想:无向边的转移作为有向边考虑.其他的就是直接上全期望公式.由于这个题目不是有向无环图,所以需要高斯消元搞一搞. 设每个点的期望经过次数是\(g(x)\),那么有 \ ...
- loj2318 「NOIP2017」宝藏[状压DP]
附带其他做法参考:随机化(模拟退火.爬山等等等)配合搜索剪枝食用. 首先题意相当于在图上找一颗生成树并确定根,使得每个点与父亲的连边的权乘以各自深度的总和最小.即$\sum\limits_{i}dep ...
- 【每日一包0008】arr-diff
[github地址:https://github.com/ABCDdouyae...] arr-diff 多个数组比较,过滤出第一个数组独有的内容 用法:arr-diff(arr1, arr2, ar ...
- mysql向redis导入数据
数据库结构如下 如果是linux系统下,如此整备数据 SELECT CONCAT( "*10\r\n", '$', LENGTH(redis_cmd), '\r\n',redis_ ...