2011-11-22 105 views
0

如何將整個文件夾添加到Velocity並將其作爲資源包使用?使用Spring框架將文件夾添加到Velocity中的類路徑

目前在我velocity.xml我有這樣的代碼:

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 
    <property name="parentMessageSource"> 
     <ref bean="globMessageSource"/> 
    </property> 
    <property name="basenames"> 
     <list> 
     <value>classpath:/WEB-INF/i18n</value> 
     <value>/WEB-INF/templates/velocity/my_vm_template</value> 
    </list> 
</bean> 

我需要的i18n文件夾添加到類路徑,使其包含的文件可以通過toolbox.xml的VelocityTools 1.4版本中可以看出:

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

的代碼是給我的錯誤信息: 「java.util.MissingResourceException:找不到捆綁的基本名稱i18n.ss_messages,地方en_US」

這個問題涉及到VelocityTools error - "java.util.MissingResourceException: Can't find bundle for base name WEB-INF.conf.resources.ss_messages, locale en_US"

對不起,如果這是一個愚蠢的問題,但我找不到任何地方描述如何將整個文件夾添加到類路徑並作爲一個捆綁包提供,因此它可以支持Velocity模板本地化。

重要提示!如果將我的ss_messages_bg_BG.properties和ss_messages_en_US.properties文件放在/ WEB-INF/classes/i18n中,那麼它可以工作,但我想將它們放在/ WEB-INF/templates/i18n中的理想文件夾中。我怎麼做?

回答

0

你使用maven嗎?你可以告訴maven使用該目錄作爲資源:

 <resource> 
      <!-- Velocity requires to be in classpath --> 
      <directory>src/main/webapp/WEB-INF/i8n</directory> 
      <filtering>true</filtering> 
     </resource> 
相關問題