我也是最近开始学习Spring Boot,在执行异步操作的时候总是汇报如下的错误:

Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No qualifying bean of type 'com.self.spring.springboot.Jeep' available
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:353)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:340)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1090)
at com.self.spring.springboot.App.main(App.java:24)

 我运行的代码如下:

Jeep类:
import java.util.concurrent.TimeUnit;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component; @Component
public class Jeep implements Runnable {

  //异步注解
@Async
public void run() {
try {
for(int i=1;i<=10;i++){
System.out.println("==============" + i);
TimeUnit.SECONDS.sleep(1);
}
} catch (Exception e) {
e.printStackTrace();
}
} }

main类:

@EnableAutoConfiguration
//使@Async注解生效
@EnableAsync
@ComponentScan
public class App { public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(App.class, args);
System.out.println(context.getBean(TomcatProperties.class));
context.getBean(Jeep.class).run();
System.out.println("===========end===========");
context.close(); } }

错误分析:错误提示没有这个 com.self.spring.springboot.Jeep' available,但是已经存在这个类,后来查询了一会,非异步操作的时候,我们通过context.getBean(类名.class)来调用这个类里面的方法,但是在异步操作的时候,调用Jeep类实现了接口Runnable的方法,我们调用context.getBean(Runnable.class).run(),才会正常运行不报错。。

其实我也不得解答,如果有哪位高手看到了,请给我留言,已解我心中之谜。。。。

spring Boot异步操作报错误: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.self.spring.springboot.Jeep' available的更多相关文章

  1. springboot 报错 org.springframework.beans.factory.NoSuchBeanDefinitionException:No qualifying bean of type 'com.example.service.HrService' available: 有没有大佬出个主意,我找了一天,刚入门springboot

    话不多说先上图,这是启动类的配置,这里配置了@ComponentScan("我的mapper的接口") 接下来是我的项目结构截图 然后是service 的截图,我在这里加了注解@S ...

  2. 添加事务后 org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type available

    今天遇到了一个奇怪的问题   在没添加事务之前  所有的代码都是好的 , 当我添加了事务之后, 代码报错 org.springframework.beans.factory.NoSuchBeanDef ...

  3. springboot启动报错:Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.zxkj.lockserver.dao.CompanyDao' available: expected at least 1 bean which qua

    Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of ty ...

  4. Caused by:org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type "" available: expected at least 1 bean which qualifies as autowire candidate

    项目使用spring, mybatis.因为分了多个模块,所以会这个模块引用了其它模块的现在,结果使用Junit测试的时候发现有两个模块不能自动注入dao和service问题.解决后在此记录一下. 解 ...

  5. 解决 org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type的问题

    具体错误如下: Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying be ...

  6. Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.qingmu.mybaitsplus.mapper.UserMapper' available:

    java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.conte ...

  7. org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [dx.service.ItemService] found for dependency

    在整合ssm框架,测试service层的时候报错 Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: ...

  8. org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.oskyhang.gbd.service.UserService] found for dependency: expected at least 1 bean which qualifies as aut

    spring中一个符号的错误居然让我浪费了四五个小时才找出来,不得不给自己了两个耳光.. 由于新建项目与原来项目的目录结构有所不同,copy过来的配置文件,有些地方修改的不彻底,导致spring扫描注 ...

  9. Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.thinkplatform.dao.UserLogDao' available: expected at least 1 bean which qualifies as autowi

    我出错的问题是: 检查:

随机推荐

  1. vue組件傳值及vuex的使用

    https://blog.csdn.net/u011175079/article/details/79161029 https://blog.csdn.net/sisi_chen/article/de ...

  2. PhotoShop不用魔棒、钢笔 建立较平整的选区 P进电脑屏幕里

    不用魔棒.抽出.钢笔等,还可以直接变形图建立调整选区,这种方法比钢笔抽出感觉简单一些,比魔棒仔细一些. 抽出或钢笔:抽出弄错了偏移了还要擦除,调整笔刷,抽出后可能还有毛边,需要用橡皮擦除: 钢笔,错了 ...

  3. Windows平台下载、安装、配置Apache全攻略

    本文介绍了如何在windows平台进行apache服务器的下载.安装和配置过程. 1.下载 首先进入apache for windows的官方下载地址[猛戳这里],依次在下列页面进行下载操作: 我这里 ...

  4. 线程池、进程池(concurrent.futures模块)和协程

    一.线程池 1.concurrent.futures模块 介绍 concurrent.futures模块提供了高度封装的异步调用接口 ThreadPoolExecutor:线程池,提供异步调用 Pro ...

  5. property与x.setter与x.deleter

    #测试property,x.setter,x.deleter class Test1: def __init__(self): self.__private = "alex" @p ...

  6. pestle.phar

    nstalll: 1,cd /usr/local/bin && curl -LO http://pestle.pulsestorm.net/pestle.phar : 2,chmod  ...

  7. python之路day04--列表的增删改查,嵌套、元组的嵌套、range、for循环嵌套

    列表增删改查 增加 append li = ['taibai','zy','nvshen'] li.append('aa') print(li) #['taibai', 'zy', 'nvshen', ...

  8. IDEA或Webstorm设置Terminal终端字体大小

    File---Settings

  9. 二.django项目环境搭建

    Ⅰ.web框架介绍 1.socket 服务端 1)客户端(手机中各种app.浏览器)是用来与服务端(网站的服务器程序)进行交互的 2)服务端类似发电厂,客户端类似电器,socket类似插座,互联网的数 ...

  10. oldboy s21day11

    #!/usr/bin/env python# -*- coding:utf-8 -*- # 1.列举 str.list.dict.set 中的常用方法(每种至少5个),并标注是否有返回值.'''str ...