NutzCN Logo
问答 velocity 集成 调用提示空指针异常
发布于 64天前 作者 qq_7fe77d10 117 次浏览 复制 上一个帖子 下一个帖子
标签:

JAR:commons-collections-3.2.1.jar,commons-lang-2.4.jar,nutz-1.r.61.r2.jar,nutz-plugins-views-1.r.61-SNAPSHOT.jar,velocity-1.7.jar
velocity-tools-2.0.jar
velocity.properties
input.encoding=UTF-8
output.encoding=UTF-8
resource.loader=webapp
webapp.resource.loader.class=org.apache.velocity.tools.view.WebappResourceLoader
webapp.resource.loader.path=/
调用方式:
@At
@Ok("vm:templates.index") // 模板文件的路径为 /WEB-INF/templates/index.vm
public String index4(){
System.out.println("begin index1 vm");
return "test";
}

17-07-17 22:29:25.483 WARN [http-nio-80-exec-1] Error@/vl/index4 :
java.lang.NullPointerException
	at org.nutz.resource.Scans.scan(Scans.java:197)
	at org.nutz.resource.Scans.loadResource(Scans.java:108)
	at org.nutz.ioc.impl.PropertiesProxy.getResources(PropertiesProxy.java:153)
	at org.nutz.ioc.impl.PropertiesProxy.setPaths(PropertiesProxy.java:109)
	at org.nutz.ioc.impl.PropertiesProxy.<init>(PropertiesProxy.java:64)
	at org.nutz.plugins.view.velocity.VelocityLayoutView.init(VelocityLayoutView.java:67)
	at org.nutz.plugins.view.velocity.VelocityLayoutView.render(VelocityLayoutView.java:85)
	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:33)
	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:202)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	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)

17 回复
PropertiesProxy propertiesProxy = new PropertiesProxy(Mvcs.getNutConfig().getInitParameter("org.apache.velocity.properties"));

web.xml里面配置一下吧

这个需要怎么配置?

                 <init-param>
			<param-name>org.apache.velocity.properties</param-name>
			<param-value>velocity.properties</param-value>
		</init-param>

目前的WEB.XML只配置了NUTZ


<filter> <filter-name>nutz</filter-name> <filter-class>org.nutz.mvc.NutFilter</filter-class> <init-param> <param-name>modules</param-name> <param-value>net.wendal.nutzbook.MainModule</param-value> </init-param> <init-param> <param-name>exclusions</param-name> <param-value>/rs/*,/druid/*</param-value> </init-param> </filter> <filter-mapping> <filter-name>nutz</filter-name> <url-pattern>/*</url-pattern> <!-- ForwardView需要下面的配置 @Ok("->:/xxx/yyy/zzz") --> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher> </filter-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list>

大致上需要什么JAR包有统计吗

java.lang.NoClassDefFoundError: org/apache/commons/digester/RuleSet
	at org.apache.velocity.tools.config.ConfigurationUtils.getDefaultTools(ConfigurationUtils.java:77)
	at org.apache.velocity.tools.view.VelocityView.configure(VelocityView.java:458)
	at org.apache.velocity.tools.view.VelocityView.init(VelocityView.java:313)
	at org.apache.velocity.tools.view.VelocityView.<init>(VelocityView.java:213)
	at org.apache.velocity.tools.view.ServletUtils.createView(ServletUtils.java:156)
	at org.apache.velocity.tools.view.ServletUtils.getVelocityView(ServletUtils.java:142)
	at org.apache.velocity.tools.view.ServletUtils.getVelocityView(ServletUtils.java:115)
	at org.nutz.plugins.view.velocity.VelocityLayoutView.getVelocityView(VelocityLayoutView.java:277)
	at org.nutz.plugins.view.velocity.VelocityLayoutView.createContext(VelocityLayoutView.java:264)
	at org.nutz.plugins.view.velocity.VelocityLayoutView.render(VelocityLayoutView.java:89)
	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:33)
	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:202)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	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)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.digester.RuleSet
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285)
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
	... 46 more

是否我整的哪里不对,怎么一个VELOCITY我已经加了这么多JAR还是不行
:commons-collections-3.2.1.jar,
commons-lang-2.4.jar,
nutz-1.r.61.r2.jar,
nutz-plugins-views-1.r.61-SNAPSHOT.jar,
velocity-1.7.jar
velocity-tools-2.0.jar
commons-digester3-3.2.jar
commons-logging-1.2.jar

JAR包问题解决了,但是模板资源找不到
WEB-INFO下面是有 templates/index.vm 的

org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'templates.index'
	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.app.VelocityEngine.getTemplate(VelocityEngine.java:373)
	at org.apache.velocity.tools.view.VelocityView.getTemplate(VelocityView.java:861)
	at org.apache.velocity.tools.view.VelocityView.getTemplate(VelocityView.java:839)
	at org.nutz.plugins.view.velocity.VelocityLayoutView.handleRequest(VelocityLayoutView.java:233)
	at org.nutz.plugins.view.velocity.VelocityLayoutView.render(VelocityLayoutView.java:92)
	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:33)
	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:202)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	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)

改成这样试试

webapp.resource.loader.path=/WEB-INF/

还是同样的错误

那再改一下试试

@Ok("vm:templates/index.vm")

换了另一个VM错误


17-07-17 23:35:59.516 ERROR [http-nio-80-exec-3] Can't load layout "layout/Default.vm" org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'layout/Default.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.app.VelocityEngine.getTemplate(VelocityEngine.java:373) at org.apache.velocity.tools.view.VelocityView.getTemplate(VelocityView.java:861) at org.apache.velocity.tools.view.VelocityView.getTemplate(VelocityView.java:839) at org.nutz.plugins.view.velocity.VelocityLayoutView.getTemplate(VelocityLayoutView.java:216) at org.nutz.plugins.view.velocity.VelocityLayoutView.mergeTemplate(VelocityLayoutView.java:196) at org.nutz.plugins.view.velocity.VelocityLayoutView.render(VelocityLayoutView.java:93) 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:33) 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:202) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) 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)

index.vm里面引用了另外一个vm吧?

这个报错是后台抛出来的 ,index.vm在前端是正常显示出来了。
只是每次调用会抛出这段异常

index.vm贴出来看看

就这么简单的

ooo3$!{obj}cc

这个错是因为velocity默认加载主模版Default.vm,但你的里面没有
可以在layout里新建Default.vm
内容写:

$screen_content

即可

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