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."的更多相关文章

  1. 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 ...

  2. 解决办法 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 ...

  3. 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版本然后 ...

  4. 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 ...

  5. 解决:Field xxMapper in xx.service.impl.xxServiceImpl required a bean of type 'xx.mapper.xxMapper'

    1.启动 SpringBoot项目报错,使用的是Springboot.Spring.Mybatis连接Mysql数据库,启动SpringBoot项目报错,错误如下所示: _____ .__/\ .__ ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

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

    运行springboot项目报错: *************************** APPLICATION FAILED TO START ************************** ...

随机推荐

  1. Caffe常用算子GPU和CPU对比

    通过整理LeNet.AlexNet.VGG16.googLeNet.ResNet.MLP统计出的常用算子(不包括ReLU),表格是对比. Prelu Cpu版 Gpu版 for (int i = 0; ...

  2. 批处理 使用默认浏览器 打开html文件

    @echo offfor /f "tokens=3,4" %%a in ('"reg query HKEY_CLASSES_ROOT\http\shell\open\co ...

  3. mybaites 入门到精通

    这个mybatis教程也不错:http://limingnihao.iteye.com/blog/781671 MyBatis 目录(?)[-] mybatis实战教程mybatis in actio ...

  4. 11jsp

    1.JSP 1. 指令 作用:用于配置JSP页面,导入资源文件 格式:             <%@ 指令名称 属性名1=属性值1 属性名2=属性值2 ... %> 分类:        ...

  5. SQL注入--盲注及报错注入

    盲注查询 盲注其实就是没有回显,不能直观地得到结果来调整注入数据,只能通过其他方式来得到是否注入成功,主要是利用了一些数据库内置函数来达到的 布尔盲注 布尔很明显Ture跟Fales,也就是说它只会根 ...

  6. ecshop新建增加独立页面的方法

    ecshop是通过php文件来指向dwt文件的,比如index.php是程序文件,那么其模板文件就是index.dwt 那么如果新建一个php文件来单独做其他作用呢?其实很简单 第一步: 将index ...

  7. zabbix的简单操作(proxy代理分布式监控)

    分布式监控 作用:分担压力,减轻负载,多机房监控 通过zabbix proxy的搭建,zabbix server可以远程从proxy获取到数据,这里的环境相当于zabbix server具有一个公网i ...

  8. 遗传算法解决寻路问题——Python描述

    概要 我的上一篇写遗传算法解决排序问题,当中思想借鉴了遗传算法解决TSP问题,本质上可以认为这是一类问题,就是这样认为:寻找到一个序列X,使F(X)最大. 详解介绍 排序问题:寻找一个序列,使得这个序 ...

  9. Istio 1.4 部署指南

    原文链接:Istio 1.4 部署指南 Istio 一直处于快速迭代更新的过程中,它的部署方法也在不断更新,之前我在 1.0 版本中介绍的安装方法,对于最新的 1.4 版本已经不适用了.以后主流的部署 ...

  10. 对Spring Boot 及Mybatis简单应用

    因为没有系统的学习过SpringBoot,在对照一个别人的SpringBoot项目,进行简单的搭建及使用. 1.首先创建SpringBoot项目之后,这里会有默认的启动类,基本不需要配置,在类的上边有 ...