spring Boot异步操作报错误: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.self.spring.springboot.Jeep' available


我也是最近开始学习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(),才会正常运行不报错。。

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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



猜您在找 springboot 报错 org.springframework.beans.factory.NoSuchBeanDefinitionException:No qualifying bean of type 'com.example.service.HrService' available: 有没有大佬出个主意,我找了一天,刚入门springboot 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 Spring 报错 :org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'statementController' available org.springframework.beans.factory.NoSuchBeanDefinitionException:No qualifying bean of type 'xxx 'available spring 框架错误 org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type 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 Caused by:org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type "" available: expected at least 1 bean which qualifies as autowire candidate Spring Boot 调用 MongoRepository时报org.springframework.beans.factory.NoSuchBeanDefinitionException错误的解决办法 解决 org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type的问题 org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'cn.yang.service.StudentInterface' available: expected at least 1 bean which qualifies as autowire candidate
 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM