简体   繁体   English

Spring @Resource期望至少有1个bean符合此依赖项的自动装配条件

[英]Spring @Resource Expected at least 1 bean which qualifies as autowire candidate for this dependency

I'm trying to run a web app and I'm having some issues. 我正在尝试运行网络应用,但遇到了一些问题。 Basically I have a controller and a process and they both share a queue. 基本上,我有一个控制器和一个进程,它们都共享一个队列。

The controller manages the files that are uploaded to the server and it puts them in the queue. 控制器管理上载到服务器的文件,并将它们放入队列中。 In the other side, the process takes the files in the queue and uses them for other things. 另一方面,该过程将文件放入队列中,并将其用于其他用途。

I've defined the queue as a LinkedBlockingQueue and the annotation @Resource on both of them, but when I run the app, the following exception appears: 我已经将队列定义为LinkedBlockingQueue和它们两个的注解@Resource,但是当我运行应用程序时,出现以下异常:

Error creating bean with name 'csvQueueConsumerBean': Injection of resource 
dependencies failed; nested exception is 
org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No qualifying bean of type [java.util.concurrent.LinkedBlockingQueue] found for 
dependency: expected at least 1 bean which qualifies as autowire candidate for this 
dependency. 

The code of both clases is the following: 这两个类别的代码如下:

@RestController
@RequestMapping("/upload")
public class FileUploadControllerW {

@Resource
protected LinkedBlockingQueue<QueueObject> csvQueue;

...
}

@Component
public class CsvQueueConsumerBean{

@Resource
protected LinkedBlockingQueue<QueueObject> csvQueue;

...
}

Just for the record, both classes are not on the same package. 仅作记录,两个类都不在同一程序包中。

The reason for this is because Spring context cannot wire the Bean called 这样做的原因是因为Spring背景不能接线Bean

csvQueueConsumerBean

You will need to initialize its LinkedBlockingQueue dependency in the Spring config file like this: 您将需要在Spring配置文件中初始化其LinkedBlockingQueue依赖关系,如下所示:

@Bean
public LinkedBlockingQueue<QueueObject> linkedBlockingQueue(){
    LinkedBlockingQueue<QueueObject> blockingQueue = new LinkedBlockingQueue<QueueObject>();
    // do what you need here...
    return blockingQueue;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring 预计至少有 1 个 bean 有资格作为此依赖项的自动装配候选者 - Spring expected at least 1 bean which qualifies as autowire candidate for this dependency NoSuchBeanDefinitionException期望至少有一个bean可以作为此依赖项的autowire候选者 - NoSuchBeanDefinitionException expected at least 1 bean which qualifies as autowire candidate for this dependency 预计至少有 1 个符合自动装配候选条件的 bean。 依赖注解 - expected at least 1 bean which qualifies as autowire candidate. Dependency annotations 自动装配:预计至少有 1 个 bean 有资格作为此依赖项的自动装配候选者 - Autowiring :expected at least 1 bean which qualifies as autowire candidate for this dependency jira rest 预计至少有 1 个 bean 有资格作为此依赖项的自动装配候选者 - jira rest expected at least 1 bean which qualifies as autowire candidate for this dependency Spring @Autowired 不工作 - 预计至少有 1 个 bean 有资格作为 autowire 候选 - Spring @Autowired not working - expected at least 1 bean which qualifies as autowire candidate 没有为依赖项找到UserRepository类型的限定bean:预期至少有1个bean符合此依赖项的autowire候选者 - No qualifying bean of type UserRepository found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency 未找到依赖项的类型为[PATHTOCLASS]的合格Bean:至少应有1个符合此依赖项自动候选条件的Bean - No qualifying bean of type [PATHTOCLASS] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency 未找到依赖项[**。Clients]的合格bean:至少应有1个合格为autowire候选对象的bean。 依赖注释:{} - No qualifying bean found for dependency [**.Clients]: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {} Crudrepository - 没有为依赖找到符合条件的 bean:预计至少有 1 个 bean 有资格作为这个依赖的自动装配候选者 - Crudrepository - No qualifying bean of type found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM