NutzCN Logo
问答 集成velocity,模板文件直接放在webapp下能访问,在webapp下的其他目录找不到模板文件是为什么
发布于 3003天前 作者 LIZQing 3364 次浏览 复制 上一个帖子 下一个帖子
标签:
@At("/")
@Ok("vm:/hello") 
public void index(){}

目录结构:
webapp
...hello.vm
...index.jsp
上面这种写法,hello.vm文件放在webapp目录能够找到
但是下面:

@At("/")
@Ok("vm:/cms/hello") 
public void index(){}

目录结构:
webapp
...cms
......hello.vm
...index.jsp
hello.vm文件放在webapp/cms目录就找不到了,提示

org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource

这是为什么啊

9 回复

你确定路径没写错???

@wendal

@At("/")
@Ok("vm:/cms/hello") 
public void index(){}

这个路径我是仿照新手入门里学的,http://www.nutzam.com/core/integration/velocity.html,里面就是这么写的啊
而且我用这个:

@At("/")
@Ok("jsp:/cms/hello") 
public void index(){}

webapp
...cms
......hello.vm
......hello.jsp
...index.jsp
也是能找到hello.jsp的,但是这个hello.vm怎么也找不到

org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource '/cms/hello.vm'

@lizqing 完整的前后报错信息

来自炫酷的 NutzCN

@wendal
这个是找不到的时候报的错

2016-09-02 12:46:49,569 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:92) DEBUG - Found mapping for [GET] path=/cms : TestAt.index(TestAt.java:10)
2016-09-02 12:46:49,575 org.nutz.plugins.view.velocity.VelocityLayoutView.render(VelocityLayoutView.java:54) DEBUG - Path::/cms/hello.vm
2016-09-02 12:46:49,740 org.nutz.plugins.view.velocity.VelocityLayoutView.render(VelocityLayoutView.java:59) ERROR - 模板引擎错误
org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource '/cms/hello.vm'
	at org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:474)
	at org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:352)
	at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1533)
	at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1514)
	at org.apache.velocity.runtime.RuntimeSingleton.getTemplate(RuntimeSingleton.java:299)
	at org.apache.velocity.app.Velocity.getTemplate(Velocity.java:358)
	at org.nutz.plugins.view.velocity.VelocityLayoutView.render(VelocityLayoutView.java:55)
	at org.nutz.mvc.impl.processor.ViewProcessor.process(ViewProcessor.java:66)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:28)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:198)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
2016-09-02 12:46:49,775 org.nutz.mvc.impl.processor.FailProcessor.process(FailProcessor.java:28) WARN  - Error@/cms :
org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource '/cms/hello.vm'
	at org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:474)
	at org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:352)
	at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1533)
	at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1514)
	at org.apache.velocity.runtime.RuntimeSingleton.getTemplate(RuntimeSingleton.java:299)
	at org.apache.velocity.app.Velocity.getTemplate(Velocity.java:358)
	at org.nutz.plugins.view.velocity.VelocityLayoutView.render(VelocityLayoutView.java:55)
	at org.nutz.mvc.impl.processor.ViewProcessor.process(ViewProcessor.java:66)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:28)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:198)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)

@wendal
这是直接放在webapp下能访问到时的输出

2016-09-02 12:53:31,793 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:92) DEBUG - Found mapping for [GET] path=/cms : TestAt.index(TestAt.java:10)
2016-09-02 12:53:31,800 org.nutz.plugins.view.velocity.VelocityLayoutView.render(VelocityLayoutView.java:54) DEBUG - Path::/hello.vm

建议下载nutzwk的Velocity版本看看

@wendal 大神我找到问题在哪了,但是不知道怎么解决,能指点一下吗
我下面这个路径:

@At("/")
@Ok("vm:/hello") 
public void index(){}

找的不是项目里面webapp下的hello.vm,是我放在桌面的hello.vm,为啥会从桌面开始加载啊,我该怎么配置下呢。。

贴一下 velocity.properties

@wendal 好吧,是我引擎初始化的问题,一开始这个https://nutz.cn/yvr/t/ppn43mg9e8ju9q1pkvhuuiqeai里面的方式没看懂,后来发现是同样的问题。。大中午的还帮忙真是麻烦了。

添加回复
请先登陆
回到顶部