【发布时间】:2009-07-22 19:12:19
【问题描述】:
我们正在开发一个大型 J2ee 电子销售解决方案。它有很多集成:CMS、ERP、邮件服务器等。所有这些系统都分为测试和生产环境。
我们需要使用测试配置将我们的应用程序部署到我们的测试服务器,并且当部署到我们的生产服务器时,它应该使用生产配置。我们如何让我们的应用程序选择正确的属性?
到目前为止,我们尝试过的事情是这样的:
我们所有的属性文件都包含测试属性和生产属性
test.mvxapi.server = SERV100TS test.mvxapi.username = 用户 test.mvxapi.password = 密码 测试.mvxapi.port = 6006 test.mvxapi.cono = 600 mvxapi.server = SERV10001 mvxapi.username = 用户 mvxapi.password = 密码 mvxapi.port = 6001 mvxapi.cono = 100
读取这些属性的 Util 有一个开关:isTest(),它在键前面加上“test”。
public String getProperty(String property)
{
return properties.getProperty(prefix + "" + property);
}
开关由我们的构建服务器创建的另一个属性设置。构建 .EAR 后,我们的生产服务器的脚本将(输入到 build.xml)“isProduction=true”注入到 system.properties。
<propertyfile file="${buildDir}/system.properties">
<entry key="isProduction" value="${systemType}"/>
</propertyfile>
我不确定这是不是最好的方法。如果由于某种原因“isProduction=false”被错误地提交到我们的生产环境中,一切都变得松散了。
我读过人们在服务器本地拥有属性。但我们真的不想让文件四处散布。我们有生产服务器集群。确保每台服务器都有正确的属性文件似乎不是万无一失的
【问题讨论】:
-
2009 年的大小已更改 :) Spring 现在可以在配置文件中执行此操作:docs.spring.io/spring-boot/docs/current/reference/html/…
标签: java jakarta-ee