beetl 模板读取的问题

tczj 发布于 2014/07/21 14:51
阅读 2K+
收藏 1

@闲.大赋 你好,想跟你请教个问题:

如何在spring mvc 中让beetl又可以读viewNames里面的模板,又可以读取jar中的模板,而且include不引响?



严重: Servlet.service() for servlet [spring-mvc] in context with path [/web.core] threw exception [Request processing failed; nested exception is java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: ATTRIBUTE_NOT_FOUND] with root cause
ATTRIBUTE_NOT_FOUND
at org.beetl.core.om.AttributeAccessFactory.buildFiledAccessor(AttributeAccessFactory.java:143)
at org.beetl.core.engine.VarAttributeNodeListener.onEvent(VarAttributeNodeListener.java:49)
at org.beetl.core.engine.StatementParser.exec(StatementParser.java:143)
at org.beetl.core.engine.StatementParser.exec(StatementParser.java:169)
at org.beetl.core.engine.StatementParser.exec(StatementParser.java:169)
at org.beetl.core.engine.StatementParser.exec(StatementParser.java:130)
at org.beetl.core.engine.StatementParser.parse(StatementParser.java:45)
at org.beetl.core.engine.BasicProgramOptProbe.check(BasicProgramOptProbe.java:50)
at org.beetl.core.engine.TypeBindingProbe.check(TypeBindingProbe.java:138)
at org.beetl.core.engine.FastRuntimeEngine$FilterProgram.execute(FastRuntimeEngine.java:42)
at org.beetl.core.Template.renderTo(Template.java:121)
at org.beetl.core.Template.renderTo(Template.java:87)
at org.beetl.ext.web.WebRender.render(WebRender.java:74)
at org.fox.beetl.ext.spring.BeetlView.renderMergedTemplateModel(Unknown Source)
at org.springframework.web.servlet.view.AbstractTemplateView.renderMergedOutputModel(AbstractTemplateView.java:167)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:264)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1201)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:986)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:933)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:851)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:844)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:106)
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:220)
at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:122)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
at org.apache.catalina.core.StandardHostValve.__invoke(StandardHostValve.java:171)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:662)




<bean name="beetlGroupTemplate" class="org.fox.beetl.ext.spring.GroupTemplateFactoryBean">
<property name="configFileResource" value="classpath:config/beetl/beetl.properties"/>
<property name="resourceLoader">
<bean class="org.fox.beetl.ext.spring.resource.SpringServletContextResourceLoader"/>
</property>
</bean>
<bean name="beetlViewResolver" class="org.fox.beetl.ext.spring.BeetlViewResolver" >
<property name="viewNames">
<list>
<value>beetl/**</value>
</list>
</property>
<property name="groupTemplate" ref="beetlGroupTemplate"/>
<property name="contentType" value="text/html;charset=UTF-8"/>
<property name="exposeRequestAttributes" value="true"/>
        <property name="exposeSessionAttributes" value="true"/>
        <property name="cache" value="true"/>
<property name="order" value="0"/>
<property name="prefix" value="/WEB-INF/"/>
<property name="suffix" value=".html"/>
</bean>

加载中
0
闲大赋
闲大赋
这个有点麻烦了,需要重写一个ResourceLoader,建议继承WebFileResourceLoader。在关键方法:

public Resource getResource(String key) 方法中,根据key值来加载模板资源,建议你参考源码自己实现一个

闲大赋
闲大赋
回复 @griftt : 看提示,你使用了ClassLoader来加载模板,你检查一下pages下是否有你的模板(不是源代码,是目标代码)
griftt
griftt
你好,我开启了beetl的自动检测就报模版加载出错了,能帮我看看吗 错找不到指定模板或者加载错(TEMPLATE_LOAD_ERROR): 位于0行 资源:/modular/html/goods/goods_add.html ClassLoader:sun.misc.Launcher$AppClassLoader@18b4aac2 Path:pages
tczj
tczj
回复 @闲.大赋 : 是标准的HttpServletRequest,我也没有去动这个内置的对像,现在都是最原始的配置,但我用2.0.8就没有这个问题,因为比新版本在198行少了个return result;
闲大赋
闲大赋
回复 @tczj : ${request.contextPath} 这个访问报的什么错啊?把详细错误贴出来。另外request是标准的httpservletrequest?
tczj
tczj
回复 @闲.大赋 : 就是用的2.0.10,我说的也是2.0.10
下一页
0
闲大赋
闲大赋
看错误,似乎没有找到属性啊。不过还是有点蹊跷,按理说控制台应该有更友好的错误信息提示,包括错误类型,错误处的上下三行文本,错误行数,错误字符等。但你这里只有错误异常。你用的是什么web服务器,还有变量request是标准的httpservletrequest吧?
tczj
tczj
回复 @闲.大赋 : 对了...最好能够极时更新到maven中央库....方便一些....现在只有2.0.8
tczj
tczj
回复 @闲.大赋 : 好的...马上升级,麻烦你了
闲大赋
闲大赋
回复 @tczj : 新版本修复了这个bug,2.0.11
闲大赋
闲大赋
回复 @tczj : 是有bug,我看看,目前暂时的方案可以使写个方法来完成你这个功能,或者使用ctxPath这个内置变量来代替
tczj
tczj
用的Tomcat7 我很简单的就在模板上用 ${request.scheme + "://" + request.serverName + ":" + request.serverPort + request.contextPath + "/"} 其它都可以得到,就request.contextPath得不到,我再发我的配置
返回顶部
顶部