当前位置: 首页 > 知识库问答 >
问题:

原因:NoSuchBeanDefinitionException:没有xxx类型的合格bean需要至少1个合格的autowire候选bean

郁高韵
2023-03-14
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;
    }

}

UnsatisfiedDependencyException:在文件[/home/x/workspace/botshop-backend-java/target/classes/far/botshop/backend/storage/filesystemStorageService.class]中创建名为“file SystemStorageService”的bean时出错:通过构造函数参数0表示不满足的依赖关系;嵌套异常是org.springframework.beans.factory.NosuchBeanDefinitionException:没有“far.botshop.backend.storage.StorageProperties”类型的合格bean可用:至少需要1个符合autowire候选的bean

你知道吗?

共有1个答案

子车新立
2023-03-14

你正试图

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

但是您还没有将StorageService定义为bean。

因此,您应该在StorageService类上添加@component注释或等效注释。

 类似资料: