2017-05-18 25 views
0

我有以下代碼波紋管:產生的原因:NoSuchBeanDefinitionException:類型XXX沒有合格的豆預計將有至少1 Bean上有資格作爲自動裝配候選人

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.

有什麼想法?

回答

0

通過StorageProperties類添加@Component Annotation。

0

您正在嘗試

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

但是你有沒有定義StorageService豆。

因此,您應該在StorageService類中添加@Component註釋或等效項。

相關問題