在servlet中加载属性文件?
问题描述:
我有一个java maven项目。我在 src / main / resources
文件夹中放置了一个属性文件。
I have a java maven project. i have placed a properties file in src/main/resources
folder.
src/main/resources
|
|___properties
|
|
|___custom_en_US.properties
我在servlet中加载属性文件如下所示。
I am loading properties file as below in servlet.
ResourceBundle bundle = ResourceBundle.getBundle("classpath:properties/custom", request.getLocale());
但是上面的行正在抛出异常,说资源未找到。我如何提供属性文件的路径?请帮助我。
but above line is throwing exception saying resource not found. How can i give path to properties file? Please help me.
谢谢!
答
摆脱classpath前缀: .getBundle(/ properties / custom)
Get rid of the "classpath" prefix.: .getBundle("/properties/custom")
classpath前缀是它不是标准,而是由一些框架定义,如spring。
The "classpath" prefix is not a standard, it is defined by some frameworks like spring.