[英]FreeMarker template loading issue
I have java application packaged into myApplication.jar having following structure: 我将Java应用程序打包到具有以下结构的myApplication.jar中:
Issue is How do i pass templates location dir to configuration? 问题是如何将模板位置目录传递给配置? I have tried with Spring Resource resource = new ClassPathResource("/templates/");
我已经尝试过使用Spring Resource resource = new ClassPathResource(“ / templates /”); but that throws exception when at resource.getFile()
但这在resource.getFile()时引发异常
My Configuration initialization code: 我的配置初始化代码:
cfg = new Configuration();
cfg.setCacheStorage(new freemarker.cache.MruCacheStorage(20, 250));
cfg.setDirectoryForTemplateLoading(dir);
cfg.setObjectWrapper(new DefaultObjectWrapper());
我在这里找到答案
cfg.setClassForTemplateLoading(getClass(), "/templates");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.