简体   繁体   English

有没有办法避免多次配置相同的信息?

[英]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. 例如,Hibernate和Apache Shiro都要求我在每个库的配置文件中指定数据库连接详细信息。 Is there any method of centralizing these values into a single file, XML or otherwise, that would make it a lot easier to manage? 是否有任何方法可以将这些值集中到一个文件,XML或其他文件中,这样可以更容易管理?

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. 如果您使用的是Spring DI,那么通过Spring XML布线文件共享配置的空间相当大......只要该库可以这样配置。 (The latter means that you need to be able to inject the configuration information; eg as a Properties object.) (后者意味着您需要能够注入配置信息;例如,作为Properties对象。)

  • Another possibility is to use something else to generate your configuration files; 另一种可能性是使用其他东西来生成配置文件; eg Chef or Puppet ... or old fashioned macros. 例如Chef或Puppet ......或老式的宏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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