当前位置: 动力学知识库 > 问答 > 编程问答 >

Java Environment Configuration Framework/Service

问题描述:

First sorry for the vague question.

I am looking for a configuration framework for Java to manage database connection strings, content paths, integration endpoints, etc. I.e. when my servlet starts up, it should be able to query a configuration service at runtime for a database connection and use that connection to bootstrap itself. Likewise, when it needs to contact a service it is integrated with, it should be able to contact the same configuration service for the URL. Obviously, those answers should be different for test environments than for production.

Does anything like that exist?

Thanks

网友答案:

I don't have experience of developing and deploying servlets, but for "normal" applications, a common approach is to have several configuration files (in whatever syntax you want, for example, XML or Java properties): one configuration file with settings for your test environment, another configuration file with settings for your production environment, and so on.

Then you use a mechanism to tell your application which configuration file it should use. The mechanism for this could be a command-line argument, a Java system property, or an environment variable. Alternatively, your application/servlet might look for a hardcoded configuration filename on its classpath, in which case you would make the environment-specific version of the configuration file available in the classpath when deploying your application/servlet.

分享给朋友:
您可能感兴趣的文章:
随机阅读: