从项目刚开始就一直关注着,因为项目一直在用Freemarker模板,新出的jfinal-undertow在第一时间就部署了。可是Freemarker模板总是找不到了。在最初版出来时就反馈给波总了。现在1.1出来后,试用了下,好像还是没有找到。不知道是不是我配置有问题
在我的配置类中配置了模板的默认路径为templates
public void configRoute(Routes routes) { routes.setBaseViewPath("/templates"); routes.add("/", MainController.class, ""); }
在测试的MainController中添加action
public class MainController extends Controller { public void index(){ setAttr("name", "Jfinal"); renderFreeMarker("demo.ftl"); } }
一直报模板找不到
[ERROR]-[Thread: XNIO-1 task-1]-[com.jfinal.core.ActionHandler.handle()]: / com.jfinal.render.RenderException: freemarker.template.TemplateNotFoundException: Template not found for name "/templates/demo.ftl". The name was interpreted by this TemplateLoader: WebappTemplateLoader(subdirPath="/", servletContext={contextPath="", displayName=null}). at com.jfinal.render.FreeMarkerRender.render(FreeMarkerRender.java:161) at com.jfinal.core.ActionHandler.handle(ActionHandler.java:106) at com.jfinal.ext.handler.ContextPathHandler.handle(ContextPathHandler.java:48) at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:86) at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61) at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:132) at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64) at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77) at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292) at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81) at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138) at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135) at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48) at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272) at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:360) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: freemarker.template.TemplateNotFoundException: Template not found for name "/templates/demo.ftl". The name was interpreted by this TemplateLoader: WebappTemplateLoader(subdirPath="/", servletContext={contextPath="", displayName=null}). at freemarker.template.Configuration.getTemplate(Configuration.java:2797) at freemarker.template.Configuration.getTemplate(Configuration.java:2599) at com.jfinal.render.FreeMarkerRender.render(FreeMarkerRender.java:156)
我试着把/templates目录放到/webapp/WEB-INF下也是一样 。
@JFinal 这个问题怎么处理 , 是需要额外添加路径配置吗?我试着用
FreeMarkerRender.getConfiguration()去配也没有成功。
项目:JFinal