2017-02-03 1 views
0

私は を取得中です。org.apache.velocity.exception.ResourceNotFoundException:リソースエラーを見つけることができません。問題を解明するのに助けてくれる人もいます。下のコードを添付しました。助けていただければ幸いです。ありがとうございます。Spring MVCでVelocityテンプレートをロード中にエラーが発生しました(org.apache.velocity.exception.ResourceNotFoundException:リソースを見つけることができません)

I placed the .vm in the class path src folder.

Controller look like 

@RequestMapping("/velocity") public String velocity(final HttpServletRequest request, final HttpServletResponse response) { final VelocityEngine ve = new VelocityEngine(); ve.setProperty("resource.loader", "class"); ve.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); ve.init(); /* next, get the Template */ final Template t = ve.getTemplate("index.vm"); /* create a context and add data */ final VelocityContext context = new VelocityContext(); context.put("members", "sharat"); /* now render the template into a StringWriter */ final StringWriter writer = new StringWriter(); t.merge(context, writer); final String Html = writer.toString(); return Html; }

春-servlet.xml

<bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer"> 
    <property name="resourceLoaderPath" value="/" /> 
</bean> 

<bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver"> 
    <property name="cache" value="true"/> 
    <property name="prefix" value=""/> 
    <property name="suffix" value=".vm"/> 
</bean> 

エラー:

org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'index.vm' 
org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:474) 
org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:352) 
org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1533) 
org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1514) 
org.apache.velocity.app.VelocityEngine.getTemplate(VelocityEngine.java:373) 

velocity.properties

resource.loader = class file.resource.loader.description = Velocity File Resource Loader file.resource.loader.class = org.apache.velocity.runtime.resource.loader.FileResourceLoader file.resource.loader.path = vm file.resource.loader.cache = false file.resource.loader.modificationCheckInterval = 0

答えて

0

は、あなたがWebアプリケーションにいる場合、あなたはどの意志、Velocity ToolsサブプロジェクトからWebappResourceLoaderをチェックする必要があり、また

resource.loader = class 

resource.loader = file 

を交換する必要がありますWebアプリケーションのルートに相対的なパスを指定するのに役立ちます。オンラインhow to configure Spring with Velocity Toolsを簡単に見つけることができます。

これ以外の場合は、file.resource.loader.pathプロパティの絶対パスを指定するか、またはWebアプリケーションコンテナの現在の実行パスにテンプレートを含むvmディレクトリが含まれていることを確認する必要があります。

+0

私は問題を解決できました。本当に助けていただきありがとうございます。 – sharat

関連する問題