JavaEE 解决方案配置最佳实践 [英] JavaEE solution configuration best practices
问题描述
我们构建了 3 层企业解决方案,这些解决方案通常由多个 webapp 和 ejbjar 模块组成,这些模块都与数据库通信并具有多个外部集成点.
We build 3-tier enterprise solutions that typically consists of several webapp and ejbjar modules that all talk to a db and have several external integration points.
每个模块通常需要自己的配置,这些配置可以在解决方案的生命周期内发生变化.部署它变成了一场噩梦,因为现在我们有 18 个属性文件,必须记住要复制和配置这些文件,还要设置数据源、队列、内存要求等.
Each module typically needs its own configurations that can change over the solution's life time. Deploying it becomes a nightmare because now we have 18 property files that must be remembered to copied over and configured also setting up data-sources, queues, memory requirements etc.
我对有更好的方法充满希望但并不乐观.我们考虑过/使用过的一些选项,每个选项都有其优缺点:
I'm hopeful but not optimistic that there can be a better way. Some options we've considered/used, each with it's pros and cons:
- 使用多个 maven 项目和持续集成(例如 hudson 或 jenkins)构建一个配置 jar,其中包含每个环境(dev、qa、prod)的所有属性文件,然后将所有内容捆绑为 EAR.但是,在生产中需要时无法轻易更改.
- 将大部分设置放在数据库中,并有一个简单的屏幕来修改它.在内部,我们可以拥有一个通用配置服务 EJB,它可以读取和修改值.每个模块都可以有一个自定义扩展版本,其中包含特定的 getter 和 setter.
- 版本控制所有属性文件,然后在生产中将其检出,并在进行更改后将其检入生产分支.
有了所有这些,您仍然需要以特定于容器的方式配置数据源和队列等:(
With all of these you still need to configure data-sources and queues etc. in a container specific way :(
推荐答案
User 一个简单的数据库表(Section、Key、Value).如果需要,请添加版本",并使用诸如 getInt(String section, String key)
User a simple database table (Section, Key, Value). Add "Version" if you need it, and wrap the entire thing in a simple ConfigurationService class with methods like getInt(String section, String key)
工作量不大,而且它使应用程序代码非常整洁,并且很容易调整配置.
Not a lot of work, and it makes the application code very neat, and tweaking with the configuration very easy.
这篇关于JavaEE 解决方案配置最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!