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. JS语法学习笔记-菜鸟教程

    现在只需要<script></script>标签 javascript通常做法是放在<head>部分中,或者放在页面底部,这样可以把他们安置在同一位置,不会干扰页面 ...

  2. JQ向上取整 和向下取整 四舍五入

    向上取整   var a = 23.2325236   var abc = Math.ceil(a); //注意:Math.ceil(a)不要单独写一行,否则向上取整失败   abc = 24;   ...

  3. laravel相关备忘

    此次笔记采用的是laravel5.1版本 1.从gitcheckout下来后,首先在env修改数据库相关 2.默认laravel没有model目录,默认有一个model文件User.php放在app里 ...

  4. linux命令详解——lsof

    lsof全名list opened files,也就是列举系统中已经被打开的文件.我们都知道,linux环境中,任何事物都是文件, 设备是文件,目录是文件,甚至sockets也是文件.所以,用好lso ...

  5. Linux部署java和tomcat的运行环境

    Linux部署java和tomcat的运行环境 1.上传下载的jdk的rpm包和tomcat的tar包,我是放到/opt目录了,文件直接去官网下载即可. 2.如果之前安装过其他版本的jdk,最好先现在 ...

  6. 脚本之SSH登录

    脚本之SSH登录 一)[python实现] 导入pxssh模块 常用的三个方法: Login() 建立ssh连接 Logout() 断开连接 Prompt() 等待系统提示符,用于等待命令执行结束 S ...

  7. fiddler4自动生成jmeter脚本

    接口.性能测试任务当遇到从浏览器或移动app自己抓包的情况出现时就变得巨苦逼了,苦在哪里?苦在需要通过抓包工具抓报文,需要通过抓包报文梳理业务逻辑.需要将梳理的逻辑编写成脚本.最最苦的情况是,自己抓包 ...

  8. Dubbo 03 Restful风格的API

    目录 Dubbo03 restful风格的API 根路径 协议 版本 用HTTP协议里的动词来实现资源的增删改查 用例 swagger(丝袜哥) OpenAPI 资源 编写API文档 整合Spring ...

  9. HTTP缓存剖析

    web浏览器会自动缓存访问过的页面,当访问同一个页面的请求时,浏览器不再从服务器中重新下载页面而是优先使用本地缓存中的页面 为什么要进行web缓存 从用户的角度来看web缓存加快了上网速度,当然这是用 ...

  10. JAVA笔记10-抽象类

    (1)abstrac关键字类修饰的类是抽象类,用abstract修饰的方法是抽象方法: (2)含有抽象方法的类必须被定义为抽象类: (3)抽象类必须被继承,抽象方法必须被重写(或者将子类也声明为抽象类 ...