从 weblogic 域目录读取配置文件

发布于 2024-11-25 16:48:09 字数 1219 浏览 1 评论 0原文

我有一个配置文件,其中列出了 Logback.xml 的所有配置详细信息,例如日志文件位置和日志级别等。我将此文件放置在 weblogic 域目录下的资源中。我的项目中还有一个属性文件,它应该指向配置文件。像这样的东西。

iam.config.file=resources/iam_config.properties

我的 logback.xml 看起来像这样

 <configuration>
  <property file="${iam.config.file}"/>
  <appender name="iamLogFileAppender" class="ch.qos.logback.core.FileAppender">
    <!-- Tests run on modern PCs show that buffering related property -->
    <!-- "ImmediateFlush" has negligible impact and will be ignored.  -->
    <File>${iam.upm.log.file}</File>
    <Append>false</Append>
    <encoder>
      <pattern>[%d] %-5p %c - %m%n</pattern>
    </encoder>
  </appender>
  <root level="ERROR">
    <appender-ref ref="iamLogFileAppender"/>
  </root>

  <logger name="aero.sita.voyager.iam" level="${iam.upm.log.logLevel}" additivity="false">
    <appender-ref ref="iamLogFileAppender" />
 </logger>
</configuration>

所以我的想法是我更改日志配置而无需重新部署。但我无法让它工作,因为部署项目时 weblogic 无法找到该文件。我如何更改

iam.config.file=resources/iam_config.properties

以正确指向该文件。谢谢。

I have a config file which lists all the configuration details for Logback.xml like the log file location and log level etc. I have this file placed in resources under the weblogic domain dir. I also have a properties file in my project which should be pointing to the config file. Something like this.

iam.config.file=resources/iam_config.properties

and my logback.xml looks like this

 <configuration>
  <property file="${iam.config.file}"/>
  <appender name="iamLogFileAppender" class="ch.qos.logback.core.FileAppender">
    <!-- Tests run on modern PCs show that buffering related property -->
    <!-- "ImmediateFlush" has negligible impact and will be ignored.  -->
    <File>${iam.upm.log.file}</File>
    <Append>false</Append>
    <encoder>
      <pattern>[%d] %-5p %c - %m%n</pattern>
    </encoder>
  </appender>
  <root level="ERROR">
    <appender-ref ref="iamLogFileAppender"/>
  </root>

  <logger name="aero.sita.voyager.iam" level="${iam.upm.log.logLevel}" additivity="false">
    <appender-ref ref="iamLogFileAppender" />
 </logger>
</configuration>

So the idea is I change the log configurations without having to redeploy. But I'm not able to get this working as weblogic is not able to find the file when the project is deployed. How can I change

iam.config.file=resources/iam_config.properties

to correctly point to the file. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟凡古楼 2024-12-02 16:48:09

您可以使用通用文件覆盖功能来打包应用程序外部的属性
http://download.oracle.com/docs/cd/E21764_01/web.1111/e13702/config.htm#i1066493
使用应用程序安装目录打包应用程序时
http://download.oracle.com/docs/cd/E21764_01/web.1111/e13702/deployunits.htm#i1047223

请注意,这需要您使用以下命令查找属性ContextClassLoader,如果您希望在不重新部署的情况下读取文件,您可能必须在部署期间使用无阶段或外部阶段模式,而不是上演:

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

You can get out the Generic File Overrides feature to package properties outside the application
http://download.oracle.com/docs/cd/E21764_01/web.1111/e13702/config.htm#i1066493
when packaging your application with an Application Installation Directory
http://download.oracle.com/docs/cd/E21764_01/web.1111/e13702/deployunits.htm#i1047223

Note that this requires you to look up the properties like this with the ContextClassLoader and if you want the file to be read without a redeploy you may have to use no-stage or external stage mode during the deployment instead of staged:

Properties myAppProps = new Properties();
InputStream iostream = Thread.currentThread().getContextClassLoader().getResourceAsStream("myCfg/myApp.properties");
myAppProps.load(iostream);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文