在我的Spring MVC应用程序应用程序中,我们维护了许多配置文件,如.properties
和.txt
文件。我想读取所有配置文件并将它们保存在应用程序上下文级别,以便我可以访问整个应用程序中的配置数据。
示例:
db.properties
db.driveClassName=packages.DataSource
db.URL=some url....
errorCodes.properties
<error-code>=<error description>
ERR001=time out error occured
ERR002=The request was tampered
ERR003=transaction id is missing
答案 0 :(得分:1)
最好的方法是使用@ConfigurationalProperties,然后它们是类型安全的,您甚至可以验证它们查看本指南http://www.baeldung.com/configuration-properties-in-spring-boot