温馨提示×

springboot怎么读取自定义properties文件

小亿
87
2024-08-12 12:41:35
栏目: 深度学习

Spring Boot可以通过在application.properties文件中指定自定义properties文件的路径来读取自定义properties文件。首先,在application.properties文件中添加以下配置:

custom.properties.location=file:/path/to/your/custom.properties

然后在应用程序中使用@PropertySource注解指定自定义properties文件的路径:

@PropertySource("file:${custom.properties.location}")

这样Spring Boot就会在启动时加载自定义properties文件,并可以通过@Value注解或Environment对象来读取自定义properties文件中的配置。

0