简体   繁体   English

原因:NoSuchBeanDefinitionException:xxx类型的合格bean至少应包含1个符合自动装配候选条件的bean。

[英]Caused by: NoSuchBeanDefinitionException: No qualifying bean of type xxx expected at least 1 bean which qualifies as autowire candidate

I have the following code bellow: 我有下面的代码如下:

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;
    }

And have the following class created: 并创建以下类:

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;
    }

}

I believe StorageProperties should be easily found, but for some reason I'm getting this error: 我认为应该容易找到StorageProperties,但是由于某些原因,我遇到了此错误:

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; UnsatisfiedDependencyException:创建文件[/home/x/workspace/botshop-backend-java/target/classes/far/botshop/backend/storage/FileSystemStorageService.class]中定义的名称为'fileSystemStorageService'的bean时出错:通过构造函数参数表示的不满意依赖性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. 嵌套的异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有类型为'far.botshop.backend.storage.StorageProperties'的合格Bean:至少应有1个有资格作为自动装配候选的Bean。

Any idea? 任何想法?

在StorageProperties类上添加@Component注释。

You are trying to 您正在尝试

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

but you haven't defined StorageService as Bean. 但您尚未将StorageService定义为Bean。

So you should add @Component annotation or equivalent over the StorageService class. 因此,您应该在StorageService类上添加@Component批注或等效项。

暂无
暂无

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

相关问题 NoSuchBeanDefinitionException:没有符合类型的合格bean <package> &#39;可用:至少有1个符合自动装配候选条件的bean - NoSuchBeanDefinitionException: No qualifying bean of type '<package>' available: expected at least 1 bean which qualifies as autowire candidate NoSuchBeanDefinitionException:没有可用类型的限定bean:预期至少有1个bean有资格作为autowire候选者 - NoSuchBeanDefinitionException: No qualifying bean of type available: expected at least 1 bean which qualifies as autowire candidate 没有可用的&#39;xxx.dao.AreaDao&#39;类型的合格Bean:预计至少有1个符合自动装配候选条件的Bean - No qualifying bean of type 'xxx.dao.AreaDao' available: expected at least 1 bean which qualifies as autowire candidate 没有可用的“xxx.xxx.xxx.xxx.MyUserDetailsService”类型的合格 bean:预计至少有 1 个有资格作为自动装配候选者的 bean - No qualifying bean of type 'xxx.xxx.xxx.xxx.MyUserDetailsService' available: expected at least 1 bean which qualifies as autowire candidate NoSuchBeanDefinitionException期望至少有一个bean可以作为此依赖项的autowire候选者 - NoSuchBeanDefinitionException expected at least 1 bean which qualifies as autowire candidate for this dependency NoSuchBeanDefinitionException: 没有为依赖找到 [Repository] ​​类型的合格 bean:预计至少有 1 个符合自动装配条件的 bean - NoSuchBeanDefinitionException: No qualifying bean of type [Repository] found for dependency: expected at least 1 bean which qualifies as autowire 没有可用类型的合格Bean:预计至少有1个合格为自动装配候选的Bean - No qualifying bean of type available: 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 没有可用的“Package.TestDaoRepo”类型的合格 bean:预计至少有 1 个 bean 有资格作为自动装配候选 - No qualifying bean of type 'Package.TestDaoRepo' available: expected at least 1 bean which qualifies as autowire candidate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM