如何根据服务器/环境动态加载服务器配置? [英] How to dynamically load server configurations depending on server/environment?

查看:152
本文介绍了如何根据服务器/环境动态加载服务器配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我设置了maven配置文件,以便能够在不同的环境(开发,演示,登台,生产等)中部署我的项目,并且可以正常运行。但是问题是,对于我拥有的每个模块(Web应用程序),我需要复制/粘贴此配置文件(它们都是属性文件)。当我需要更改环境/服务器配置(例如,当端口号更改时,我需要重新部署所有EAR文件)时,这将是开销。

Currently I setup maven profiles to be able to deploy my project for different environments (dev, demo, staging, production, ...) and it works perfectly fine. But the issue is that for each module (web application) that I have, I need to copy/paste this configuration files ( they are all property files). This will be an overhead when I need to change an environment/server configuration (for example when a port number changes I need to redeploy all my EAR files).

我的问题是,是否还有其他通用解决方案可以防止这种冗余方法?例如在weblogic中设置我的属性文件(或任何其他配置文件)?
我想出了一个小模块来保存配置,并通过@Remote(EJB)对其进行调用,但是基于我组织的应用程序关系,它还有很多其他缺点。

My question is, is there any more generic solution to prevent from such redundant approach? for example to set up my property files (or any other configuration file) in weblogic? I came up with a small module to keep the configurations and call them via @Remote (EJB) but that has lots of other drawbacks base on my organization's applications relationships.

所以对我而言,最好的方法可能是能够在weblogic中设置一些配置,并在应用程序运行时动态访问它们,然后基于此决定。

So best approach for me could be to be able to setup some configurations in weblogic and get access to them dynamically when the application is running and then decide base on that.

推荐答案

我想出了另一种解决方案,我认为它对我和我的组织更好。

There is an alternative solution that I came up with and I think it better works for me and my organization.

I将具有一个位于客户端(开发人员)和系统之间的JAR。这样JAR将从 .properties 文件(或任何文件)中读取文件,该文件被定义为服务器内部的环境变量(每个服务器将采用自己的设置)。然后,在JAR中,我读取了文件并将返回请求的值。这将使开发人员仅专注于其代码,他们可以从JAR调用 getCurrentServer() getServer(XXX) (考虑到适当的异常处理很重要)。

I will have a JAR that stands between the client (developer) and system. So that the JAR will read from a .properties file (or any file) which is defined as environment variable inside the server (each server will adopt its own settings). Then inside the JAR, I read the file and will return the requested values. This will let developers just focus on their code and they can call getCurrentServer() or getServer(XXX) from the JAR (considering that appropriate exception handling is important).

现有模块应进行更新和重新部署。此实现的唯一缺点是,如果更改 .properties 文件,则需要重新启动服务器,因为文件加载机制将只有一次(实现singlton模式) )以获得更好的性能。无论如何,我认为这没什么大不了的,因为该文件可能很少更改(最多每年一次或两年一次),因此值得重新启动服务器(或者我可以随时加载文件)客户端请求,因此无需重新启动服务器-但这会对性能产生不良影响-)。

Existing modules should be updated and redeployed. The only drawback for this implementation would be if I change the .properties file, then I need to restart the server, Because the file loading mechanism will be just once (implementing singlton pattern) for better performance. Anyways, I don't think it is a big deal, because that file might change very rarely (at most once a year or once in two years), so it does worth to restart the server (or I can load the file any time the client requested so that there is no need to restart the server - but it will have bad impact on performance -).

-更新
我实现了另一个方法来访问JAR的private方法并调用 loadProperties()方法。这样,我可以手动重新加载属性,而无需重新启动服务器。

- update I implemented another method to access the private method of the JAR and call loadProperties() method. By doing this, I can manually reload the properties without restarting the server.

这篇关于如何根据服务器/环境动态加载服务器配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆