VelocityTools error - “java.util.MissingResourceEx

2019-03-03 23:13发布

问题:

I'm trying to integrate VelocityTools.ResourceTool to localize velocity template but whatever I use as the 'bundles' parameter I keep getting the following error:

java.util.MissingResourceException: Can't find bundle for base name 
WEB-INF.conf.resources.ss_messages, locale en_US

I'm using VelocityTools v1.4. Here are my configurations:

Tool config /WEB-INF/conf/misc/velocity/toolbox.xml

<tool>
  <key>test</key>
  <scope>request</scope>
  <class>org.apache.velocity.tools.generic.ResourceTool</class>
  <parameter name="bundles" value="WEB-INF.conf.resources.ss_messages"/>
  <parameter name="locale" value="en_US"/>
</tool>

Bundles:

\WEB-INF\conf\resources\ss_messages_bg_BG.properties
\WEB-INF\conf\resources\ss_messages_en_US.properties

The two files have simple content:

full.name=\u0421\u0442\  (for bg_BG.properties)
full.name=Joe Blow       (for en_US.properties)

My Velocity template has this code:

HELLO $test.full.name

I tried different values for the name="bundles" above i.e., /WEB-INF/conf/resources/ss_messages and ./conf/resources/ss_messages (going to the root dir and then referencing the ss_messages bundle).

Also, I tried putting my ss_messages.properties bundle files in a resources folder in the root and use the value="resources" instead, but nothing seems to be working...still getting the same error message.

What am I doing wrong?! Is it that the toolbox.xml file is not in the root? I've been using successfully the toolbox.xml throughout my application up until now.

回答1:

The resources should be on the classpath, and configured as such.

See the ResourceTool API docs.