Spring Boot使用@ConfigurationProperties获取yml配置为null值

仔细查看你的yml文件名,它只能是:application.yml(注意是小写application)
这些都不对:Application.ymldev-application.ymlsettings.yml

另外容易犯的错误:

1 在类中忘记了加setter方法。

2 声明类的时候注解:
@Component
@ConfigurationProperties(prefix = “student”)

3 使用的时候忘记自动加载:
@Autowired
Student student;

猜你喜欢

转载自blog.csdn.net/weixin_44215363/article/details/109274440