在gradle中仅此一个与freemaker有关的依赖配置
compile group: 'org.nutz', name: 'nutzboot-starter-freemarker', version: '2.1.5'
在application.properties中有关配置
freemarker.suffix=.ftl
模板文件资源位置:src-main-resources-template
在ide中跑是正常的,可以正确显示模板内容在client端,但是打包发布到生产环境会抛出以下异常:
org.nutz.ioc.IocException: IocBean[webHomeModule] throw Exception when creating
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:152)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:240)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:270)
at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:116)
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 com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.nutz.mvc.WhaleFilter.doFilter(WhaleFilter.java:159)
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:496)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
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:803)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: IocBean[webHomeModule] fail at field=[freeMarkerConfigurer]
at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:67)
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:138)
... 35 common frames omitted
Caused by: org.nutz.ioc.IocException: IocBean[freeMarkerConfigurer] throw Exception when creating
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:152)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:240)
at org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:60)
at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
... 37 common frames omitted
Caused by: java.lang.NullPointerException: null
at freemarker.cache.FileTemplateLoader$1.run(FileTemplateLoader.java:121)
at freemarker.cache.FileTemplateLoader$1.run(FileTemplateLoader.java:119)
at java.security.AccessController.doPrivileged(Native Method)
at freemarker.cache.FileTemplateLoader.<init>(FileTemplateLoader.java:119)
at freemarker.cache.FileTemplateLoader.<init>(FileTemplateLoader.java:98)
at freemarker.template.Configuration.setDirectoryForTemplateLoading(Configuration.java:1481)
at org.nutz.boot.starter.freemarker.FreeMarkerConfigurer.initFreeMarkerConfigurer(FreeMarkerConfigurer.java:110)
at org.nutz.boot.starter.freemarker.FreeMarkerConfigurer.init(FreeMarkerConfigurer.java:75)
at org.nutz.boot.starter.freemarker.FreeMarkerConfigurer$FM$init$62febe830a4a6764c634d9e263964cee.invoke(FreeMarkerConfigurer.java)
at org.nutz.ioc.impl.ObjectMakerImpl$2.trigger(ObjectMakerImpl.java:180)
at org.nutz.ioc.weaver.DefaultWeaver.onCreate(DefaultWeaver.java:89)
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:141)
... 40 common frames omitted
看了以下fm的文档,有关资源读取的方式如下
Built-in template loaders
void setDirectoryForTemplateLoading(File dir):
void setClassForTemplateLoading(Class cl, String basePackagePath)
void setServletContextForTemplateLoading(Object servletContext, String path)
又看了下starter初始化源码
protected void initFreeMarkerConfigurer() throws IOException, TemplateException {
String path = freemarkerDirectiveFactory.getFreemarker();
File file = Files.findFile(path);
if (!Lang.isEmpty(file)) {
Properties p = new Properties();
p.load(Streams.fileIn(file));
configuration.setSettings(p);
}
File f = Files.findFile(prefix);
configuration.setDirectoryForTemplateLoading(f);
}
貌似只提供了一种读取的方式,请问该如何解决?谢谢