报错信息如下: 2019-03-02 09:47:53 [ERROR]-[Thread: XNIO-1 task-1]-[com.jfinal.core.ActionHandler.handle()]: /api com.jfinal.render.RenderException: freemarker.template.TemplateNotFoundException: Template not found for name "/src/main/webapp/WEB-INF/ftl/api/api.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.SessionRestoringHandler.handleRequest(SessionRestoringHandler.java:119) 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:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: freemarker.template.TemplateNotFoundException: Template not found for name "/src/main/webapp/WEB-INF/ftl/api/api.ftl". The name was interpreted by this TemplateLoader: WebappTemplateLoader(subdirPath="/", servletContext={contextPath="", displayName=null}). at freemarker.template.Configuration.getTemplate(Configuration.java:1833) at freemarker.template.Configuration.getTemplate(Configuration.java:1646) at com.jfinal.render.FreeMarkerRender.render(FreeMarkerRender.java:156) ... 34 more
报错信息如上:
已经在jfinalConfig中添加了
public void configConstant(Constants me) { loadConfig(); me.setDevMode(p.getBoolean("devMode", false)); me.setViewType(ViewType.FREE_MARKER); // 支持 Controller、Interceptor 之中使用 @Inject 注入业务层,并且自动实现 AOP me.setInjectDependency(true); me.setBaseUploadPath("/upload"); } public void configRoute(Routes me) { //me.setBaseViewPath("/src/main/webapp/WEB-INF/ftl"); me.setBaseViewPath("/WEB-INF/ftl"); //全局路径 me.add("/", IndexController.class); //客户端API路径 me.add("/clientapi", ClientAPIController.class); //登录路径 me.add("/login", LoginController.class); me.add("/api", APIController.class,"/api"); me.add("/common", CommonCtroller.class); }
在undertow.txt中添加了
# js、css 等等 web 资源存放的目录 undertow.resourcePath=webapp, /src/main/webapp, src/main/webapp
api.ftl文件在项目中的路径如下:
src/main/webapp/WEB-INF/ftl/api/api.ftl
但是依旧报以上的错误,萌新已经找不出问题在哪里了。
项目:JFinal
注意最前方有一个 "/" 字符,可能是 routes.setBaseViewPath(...) 有错误,要配置成:
me.setBaseViewPath("/WEB-INF/ftl");
此外,undertow.resourcePath 的配置可以删掉,因为你的项目是标准的 maven 项目,默认会配置好