第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

創(chuàng)建 bean 時出錯 - 在服務(wù)中注入配置類不起作用

創(chuàng)建 bean 時出錯 - 在服務(wù)中注入配置類不起作用

Qyouu 2023-12-21 10:48:03
我嘗試實(shí)現(xiàn)一個 REST 服務(wù),如本教程中所示: 教程但我收到了這個錯誤:Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fileStorageService' defined in file: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.airgnb.service.FileStorageService]: Constructor threw exception; nested exception is java.lang.NullPointerExceptionCaused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.airgnb.service.FileStorageService]: Constructor threw exception; nested exception is java.lang.NullPointerExceptionCaused by: java.lang.NullPointerException服務(wù)等級:@Servicepublic class FileStorageService {    private final Path fileStorageLocation;    @Autowired    public FileStorageService(FileStorageProperties fileStorageProperties) {        this.fileStorageLocation = Paths.get(fileStorageProperties.getUploadDir())            .toAbsolutePath().normalize();        try {            Files.createDirectories(this.fileStorageLocation);        } catch (Exception ex) {            throw new FileStorageServiceException("Could not create the directory where the uploaded files will be stored.", ex);        }    }}配置類別:@Configuration@ConfigurationProperties(prefix = "file")public class FileStorageProperties {    private String uploadDir;    public String getUploadDir() {        return uploadDir;    }    public void setUploadDir(String uploadDir) {        this.uploadDir = uploadDir;    }}該應(yīng)用程序也注釋如下:@SpringBootApplication@EnableConfigurationProperties({FileStorageProperties.class})public class TestApp implements InitializingBean {我認(rèn)為唯一不同的是我使用 application.yml 而不是 application.properties,但我定義的屬性與教程類似,但只是采用 yml 樣式。我不知道為什么FileStorageProperties沒有注入,因此FileStorageService無法創(chuàng)建。@Import(FileStoroageProperties.class)我已經(jīng)嘗試使用其他一些依賴注入方式(例如字段注入)來注釋應(yīng)用程序。
查看完整描述

1 回答

?
蕭十郎

TA貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超13個贊

我認(rèn)為沒有FileStorageProperties被注射。該錯誤表明未FileStorageProperties找到該類型的 Bean。你只有一個NullPointerException構(gòu)造函數(shù)內(nèi)部。

我想fileStorageProperties.getUploadDir()回來了null。

file.uploadDir您是否在 application.yml 或 application.properties 中設(shè)置了該屬性?


查看完整回答
反對 回復(fù) 2023-12-21
  • 1 回答
  • 0 關(guān)注
  • 245 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號