Announcement Announcement Module
Collapse
No announcement yet.
Configuration / Settings Best Practice? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Configuration / Settings Best Practice?

    What is the best practice pattern for managing multiple configuration files within Spring? I have a web application that has several properties files that store a myriad of settings.

    For example, user.properties stores user specific information: the directory location of profiles, where certain icons are located, the amount of seconds someone has before a timeout occurs, etc. Another property file contains images-related properties: the maximum height and width of an uploadable image, size restrictions, etc.

    I would like to migrate all these properties into the Spring Bean framework, but I don't know how to proceed. I would like to keep these settings in multiple files, but I don't know how to specify several files into several contexts.

    Lastly, I would like these files to be reloadable at runtime. In other words, if I edit the files at runtime, I would like Spring to determine that the file has been updated, and reload it.

    Any recommendations?

  • #2
    Loading contexts in a web app is done using the ContextLoaderListener (or Servlet). Context locations are specified using hte contextConfigLocation parameter. You can specify more than just one context there (separated by a space). The values you put in there will all be treated org.springframework.core.io.Resource patterns, meaning that you can use classpath:, http://, file: prefixes. If running in a webapp, you can also use /WEB-INF/xxx.xml to load files from there (which is done very often).

    Most people split context files according to the things they contain (business logic, helpers, DAOs, etcetera) but there's no real naming scheme involved or anything. It's all up to you!

    Properties files don't have to be all migrated to Spring, have a look at the PropertiesPlaceholderConfigurer or PropertiesOverrideConfigurer for information on putting in tokens in your context files.

    Hope this helps,

    regards,
    Alef Arendsen

    Comment

    Working...
    X