如何在类路径上添加外部资源(属性文件),以便可以读取war? [英] How to add external resources (properties file) on to the classpath so that war can read?

查看:74
本文介绍了如何在类路径上添加外部资源(属性文件),以便可以读取war?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将外部目录(具有config.properties)添加到类路径中时,我们有一个小问题。如果将其添加到类路径,则应该能够在Web应用程序中读取它。 Web应用程序中有一些Spring应用程序,它们将读取外部属性文件。我在哪里找不到正确的解决方案?

We have small problem in adding the external directory (having config.properties) to the classpath. If we add this to the classpath, we should be able to read it in the web application. There are some spring applications in web application which will read the external properties file. I don't find the correct solution any where ? Could you please point me the right direction ?

谢谢,
Rama Krishna

Thanks, Rama Krishna

推荐答案

我有类似的要求,并且执行了以下操作:

I had the similar requirement and I did the followings:

1)在catalina.properties中添加了针对shared.loader的properties文件夹路径。
示例:

1) Added the properties folder path against shared.loader in catalina.properties. Example:

    shared.loader="c:/ExternalResource"

2)然后使用以下内容读取属性:-

2) Then read the properties using the following :-

Thread.currentThread().getContextClassLoader().getResourceAsStream(propertiesFileName)

这篇关于如何在类路径上添加外部资源(属性文件),以便可以读取war?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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