【发布时间】:2017-10-18 21:14:39
【问题描述】:
我有以下代码:
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: 否 符合条件的 bean 类型 'far.botshop.backend.storage.StorageProperties' 可用:预计在 至少 1 个 bean 有资格作为自动装配候选者。
有什么想法吗?
【问题讨论】:
标签: java spring spring-mvc dependency-injection