在spring mvc应用程序中维护属性文件的最佳方法

时间:2017-08-02 08:17:05

标签: java

在我的Spring MVC应用程序应用程序中,我们维护了许多配置文件,如.properties.txt文件。我想读取所有配置文件并将它们保存在应用程序上下文级别,以便我可以访问整个应用程序中的配置数据。

示例:

  1. db.properties

    db.driveClassName=packages.DataSource
    db.URL=some url....
    
  2. errorCodes.properties

    <error-code>=<error description>
    
    ERR001=time out error occured
    ERR002=The request was tampered
    ERR003=transaction id is missing
    

1 个答案:

答案 0 :(得分:1)

最好的方法是使用@ConfigurationalProperties,然后它们是类型安全的,您甚至可以验证它们查看本指南http://www.baeldung.com/configuration-properties-in-spring-boot