gpt4 book ai didi

java - 由 : NoSuchBeanDefinitionException: No qualifying bean of type xxx expected at least 1 bean which qualifies as autowire candidate 引起

转载 作者:行者123 更新时间:2023-11-30 07:54:25 25 4
gpt4 key购买 nike

我有下面的代码:

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: 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.

有什么想法吗?

最佳答案

你正在尝试

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

但您还没有将 StorageService 定义为 Bean。

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

关于java - 由 : NoSuchBeanDefinitionException: No qualifying bean of type xxx expected at least 1 bean which qualifies as autowire candidate 引起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44058210/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com