java Properties could not be found错误
跟着spring tutorial学习的过程中,在学到上传文件 https://spring.io/guides/gs/uploading-files/
的时候按照原文代码编译报错了,错误如下
1 | Parameter 0 of constructor in com.example.uploadingfiles.storage.FileSystemStorageService required a bean of type 'com.example.uploadingfiles.storage.StorageProperties' that could not be found. |
大意是说定义的property没有找到,但是在入口不是使用了@SpringApplication注解吗,怎么会扫描不到呢,后来Google一番,发现说是被覆盖掉了,经过一番折腾终于解决了。
解决办法就是需要在你的property添加@Component
注解,这样就能被发现了。
最开始的时候还遇到了这个报错
1 | @ConfigurationProperties Spring Boot Configuration Annotation Processor not found in classpath |
解决办法是安装依赖 spring-boot-configuration-processor
更新pom.xml
参考
扫描二维码,分享此文章