Tomcat\bin 文件夹中的属性文件获取 java.util.MissingResourceException [英] Property file in Tomcat\bin folder getting java.util.MissingResourceException

查看:25
本文介绍了Tomcat\bin 文件夹中的属性文件获取 java.util.MissingResourceException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 ResourceBundleTomcat\bin 文件夹中读取属性文件.当我将我的属性文件放在项目的根文件夹中时,我能够读取这个文件.但是当我把它放在 Tomcat\bin 文件夹中时,我得到了 java.util.MissingResourceException.这是怎么引起的,我该如何解决?

I want to read a properties file from Tomcat\bin folder using ResourceBundle. When I put my properties file in project's root folder, I am able to read this file. But when I put it in Tomcat\bin folder, I'm getting java.util.MissingResourceException. How is this caused and how can I solve it?

推荐答案

你需要把它放在类路径中.Tomcat/bin 文件夹不是 web 应用程序的默认运行时类路径的一部分.如果您打算在 Tomcat 中运行的 webapp 的类路径中添加一个外部文件夹,那么您需要在 Tomcat/conf/的 shared.loader 属性中指定该文件夹的路径catalina.properties 文件.但是,我会选择与 Tomcat/bin 不同的文件夹.

You need to put it in the classpath. The Tomcat/bin folder is not part of the webapp's default runtime classpath. If you intend to add an external folder to the classpath of a webapp running in Tomcat, then you need to specify the path to that folder in the shared.loader property of the Tomcat/conf/catalina.properties file. I would however choose a different folder than the Tomcat/bin.

与问题无关ResourceBundle API 旨在读取资源包文件(具有本地化内容,以便您可以国际化您的应用程序),而不是读取简单的属性文件(带有配置设置).为此,您应该使用 java.util.属性 而不是滥用 java.util.ResourceBundle.

Unrelated to the problem, the ResourceBundle API is meant to read resourcebundle files (with localized content so that you can internationalize your app), not to read simple properties files (with configuration settings). For that you should be using java.util.Properties instead and not abuse the java.util.ResourceBundle.

Properties properties = new Properties();
properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("/config.properties"));
// ...

这篇关于Tomcat\bin 文件夹中的属性文件获取 java.util.MissingResourceException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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