[英]Spring boot freemarker
I get this exception when I try to import JspTaglibs in a spring boot application. 当我尝试在Spring Boot应用程序中导入JspTaglibs时,出现此异常。
freemarker.template.TemplateModelException: No mapping defined for http://www.springframework.org/tags/form
freemarker.template.TemplateModelException:没有为http://www.springframework.org/tags/form定义映射
Hear is part of my ftl file, when I try to import it. 当我尝试导入文件时,它是我的ftl文件的一部分。
<#import "/spring.ftl" as spring/>
<#assign form=JspTaglibs["http://www.springframework.org/tags/form"] />
Get this problem only when starting the application as a spring boot app, works if deployed on standalone tomcat with a war file. 仅当以Spring Boot应用程序启动该应用程序时才出现此问题,如果将其部署在带有war文件的独立tomcat上,则可以正常工作。
Any ideas ? 有任何想法吗 ?
You need to add the code below to give templates path. 您需要添加以下代码以提供模板路径。
@Configuration
public class EmailConfiguration {
@Bean(name ="freemarkerConfig")
public FreeMarkerConfigurer getFreemarkerConfig() {
FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
configurer.setTemplateLoaderPath("**classpath:mail**/");
Map<String, Object> map = new HashMap<>();
map.put("xml_escape", new XmlEscape());
configurer.setFreemarkerVariables(map);
return configurer;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.