如何在 JBoss 中创建全局上下文变量?
这是我不久前发布的问题的后续内容:“我可以在多个环境中使用单个 WAR 吗?”。我能够在 Tomcat 中创建单一战争解决方案,但现在我们正在将应用程序迁移到 JBoss 4.2,我不知道如何设置全局环境变量。
在 Tomcat 6 中,这非常简单:我只需将以下代码片段放入 tomcat/conf/Catalina/myappname.xml 中:
<Context ...>
<Environment name="TARGET_ENV" value="DEV" type="java.lang.String" override="false"/>
</Context>
然后在我的应用程序中,我能够使用以下内容解析环境名称
Context context = (Context) InitialContext().lookup("java:comp/env");
String targetEnvironment = (String) context.lookup("TARGET_ENV");
:是我找不到在 JBoss 中放置全局变量的位置/方式。我尝试将
标记放入以下文件中,但无济于事:
server/all/deploy/jboss-web.deployer/context.xml
server/default/deploy/jboss-web.deployer/context.xml
我知道我可以将环境变量放入应用程序的 web.xml 中,但这违背了进行统一战争的目的 - 我仍然需要用于开发、质量保证和生产的自定义 .war。
我是 JBoss 新手,因此如果有任何其他信息有帮助,请告诉我,我将附加到这个问题。
This is a follow-up to a question I posted a while back: "Can I use a single WAR in multiple environments?". I was able to create a single-war solution in Tomcat, but now we are migrating our app to JBoss 4.2 and I can't figure out how to set up global environment variables.
In Tomcat 6 this was pretty straightforward: I simply put the following snippet in tomcat/conf/Catalina/myappname.xml
:
<Context ...>
<Environment name="TARGET_ENV" value="DEV" type="java.lang.String" override="false"/>
</Context>
Then in my app I was able to resolve the environment name with the following:
Context context = (Context) InitialContext().lookup("java:comp/env");
String targetEnvironment = (String) context.lookup("TARGET_ENV");
The problem is that I can't find out where/how to place global variables in JBoss. I've tried putting the <Environment>
tag in the following files to no avail:
server/all/deploy/jboss-web.deployer/context.xml
server/default/deploy/jboss-web.deployer/context.xml
I know that I can put environment variables in my app's web.xml but that defeats the purpose of having a unified war - I'd still need custom .war's for dev, qa and prod.
I'm a JBoss newbie so if there's any additional information that would help just let me know and I'll append to this question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用类似于 PropertiesService 的内容来获取数据库 url 和其他与环境相关的内容。
因此,我摆脱了提供不同环境相关工件的负担。
I use somehing similar to PropertiesService for database url, and other environment related things.
Therefore I'm relieved from the burden to provide different environment related atrifacts.