带有 Weblogic 的外部属性文件 [英] External properties file with Weblogic

查看:78
本文介绍了带有 Weblogic 的外部属性文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找将外部属性文件与将部署在 Weblogic 10.3 服务器上的应用程序一起使用的最佳方法.我在网站上阅读了许多文章,但我不想硬编码属性文件的路径或将文件放在 domain/mydomain 文件夹中.

I'm looking for the best way to use an external properties file with an application that is going to be deployed on Weblogic 10.3 server. I read a number of articles on the site but I don't want to hard-code the path to the properties file or put the file in the domains/mydomain folder.

是否有动态的方式来执行此操作,以便在部署应用程序时,属性文件也安装在例如部署文件夹下并从那里读取?

Is there a dynamic way of doing this so when the application is deployed the properties file is also installed for example under the deployments folder and read from there?

非常感谢

推荐答案

另一种不需要将文件放在其他应用程序将读取它的地方的替代方法是使用通用文件加载覆盖:http://download.oracle.com/docs/cd/E21764_01/web.1111/e13702/config.htm#i1066493

Another alternative that does not require putting the file in a place other applications will read it is to use the Generic File Loading Overrides: http://download.oracle.com/docs/cd/E21764_01/web.1111/e13702/config.htm#i1066493

这涉及创建一个目录,该目录将作为您部署的根目录,我们称之为 FooApplication,其中包含 FooApplication.ear 和 FooWeb.war.这称为应用程序安装目录.您的应用程序位于 FooApplication/app 子目录中,无论它是档案(如 .ear、.war、jar)还是这些档案之一的分解版本.您的可选部署计划(您必须有一个才能使用此功能,它可能是一个计划,除了指定文档中描述的 config-root 元素和值外,不会做太多事情)进入 FooApplication/plan.您可以将要覆盖的属性放在应用程序中的 FooApplication/plan/AppFileOverrides 目录结构中.http://download.oracle.com/docs/cd/E21764_01/web.1111/e13702/deployunits.htm#sthref9

This involves creating a directory that will be the root directory of your deployment, let's call it FooApplication that has FooApplication.ear and FooWeb.war. This is called the Application Installation Directory. Your application goes in the FooApplication/app sub-directory whether it is an archive (like .ear, .war, jar) or whether it is an exploded version of one of those archives. Your optional deployment plan (you must have one to use this feature, it could be a plan that does not do much beyond specifying a config-root element and values as described in the documentation) goes in the FooApplication/plan. You can put your properties that you want to override ones in the application in FooApplication/plan/AppFileOverrides directory structure. http://download.oracle.com/docs/cd/E21764_01/web.1111/e13702/deployunits.htm#sthref9

一旦这种部署风格完成,你就可以从你的应用程序中编写这样的代码,并且从 FooApplication/plan/AppFileOverrides/FooWeb.war/myApp.properties 中读取的 myApp.properties 的内容将是实际的文件读入.

Once that style of deployment is done, you write code like this from your application and the contents of myApp.properties get read from the FooApplication/plan/AppFileOverrides/FooWeb.war/myApp.properties will be the actual file that is read in.

Properties myAppProps = new Properties();
InputStream iostream =
Thread.currentThread().getContextClassLoader().getResourceAsStream("myCfg/myApp.properties");
myAppProps.load(iostream);

这是通过向您的应用程序添加类加载器来实现的,如文档中所述.最初配置可能看起来很乏味,但它是直接满足原始问题且仅适用于该特定应用程序的功能.

This is accomplished by adding a classloader to your application as explained in the docs. It might seem tedious to initially configure, but it is a feature that directly satisfies the original question and only for that particular application.

这篇关于带有 Weblogic 的外部属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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