原因:NoSuchBeanDefinitionException:xxx类型的合格bean至少应包含1个符合自动装配候选条件的bean。 [英] Caused by: NoSuchBeanDefinitionException: No qualifying bean of type xxx expected at least 1 bean which qualifies as autowire candidate

查看:195
本文介绍了原因:NoSuchBeanDefinitionException:xxx类型的合格bean至少应包含1个符合自动装配候选条件的bean。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码如下:

package far.botshop.backend.controller;

/**
 */
import java.util.logging.Logger;

import far.botshop.backend.storage.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Controller
public class FileUploadController {

    private final StorageService storageService;

    @Autowired
    public FileUploadController(StorageService storageService) {
        this.storageService = storageService;
    }

并创建以下类:

package far.botshop.backend.storage;

import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties("storage")
public class StorageProperties {
    /**
     * Folder location for storing files
     */
    private String location = "upload-dir";

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

}

我相信应该很容易找到StorageProperties ,但由于某种原因,我遇到此错误:

I believe StorageProperties should be easily found, but for some reason I'm getting this error:


UnsatisfiedDependencyException:创建名称为
'fileSystemStorageService'的bean时出错文件
[/home/x/workspace/botshop-backend-java/target/classes/far/botshop/backend/storage/FileSystemStorageService.class]:
通过构造函数参数0表示的不满意依赖性;
嵌套异常是
org.springframework.beans.factory.NoSuchBeanDefinitionException:没有
个类型为
的合格Bean可以使用 far.botshop.backend.storage.StorageProperties类型:预期为
至少有1个可以成为自动装配候选者的bean。

UnsatisfiedDependencyException: Error creating bean with name 'fileSystemStorageService' defined in file [/home/x/workspace/botshop-backend-java/target/classes/far/botshop/backend/storage/FileSystemStorageService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'far.botshop.backend.storage.StorageProperties' available: expected at least 1 bean which qualifies as autowire candidate.

有什么想法吗?

推荐答案

在StorageProperties类上添加@Component注释。

Add @Component Annotation over StorageProperties class.

这篇关于原因:NoSuchBeanDefinitionException:xxx类型的合格bean至少应包含1个符合自动装配候选条件的bean。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆