简体   繁体   中英

Is there a way to avoid configuring the same information multiple times?

My application utilizes many libraries that each require their own configurations.

For example, both Hibernate and Apache Shiro requires me to specify database connection details in the configuration files of each library. Is there any method of centralizing these values into a single file, XML or otherwise, that would make it a lot easier to manage?

In this situation, you can either

  • configure the libraries programatically, without configuration files, using a common framework. eg Spring.
  • generate the configuration files using templates for each configuration file and a shared set of properties.

There is no universal solution. Each library (typically) has its own way of doing configuration that isn't conducive for sharing with other libraries.

  • If you were using Spring DI, then there is considerable scope for sharing configuration via Spring XML wiring files ... provided that the library is configurable that way. (The latter means that you need to be able to inject the configuration information; eg as a Properties object.)

  • Another possibility is to use something else to generate your configuration files; eg Chef or Puppet ... or old fashioned macros.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM