我有以下代码:
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,但是由于某些原因,我遇到了此错误:
UnsatisfiedDependencyException:创建名称为bean的错误
文件中定义的“ fileSystemStorageService”
[/home/x/workspace/botshop-backend-java/target/classes/far/botshop/backend/storage/FileSystemStorageService.class]:
通过构造函数参数0表示的不满足的依赖关系;
嵌套异常为
org.springframework.beans.factory.NoSuchBeanDefinitionException:否
类型的合格豆
可用的“ far.botshop.backend.storage.StorageProperties”:预计在
至少1个符合自动装配候选条件的bean。
任何的想法?
最佳答案
在StorageProperties类上添加@Component注释。
关于java - 原因:NoSuchBeanDefinitionException:xxx类型的合格bean至少应包含1个符合 Autowiring 候选条件的bean。,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44058210/