美文网首页
6、spring boot报错总结

6、spring boot报错总结

作者: ltjxwxz | 来源:发表于2018-02-02 10:42 被阅读0次

spring boot做web开发的好处是自带web容器,最后所有文件都打在jar包里,使用jar包直接启动很方便。
1、打包后freemarker找不到模板文件
java.io.FileNotFoundException:/BOOT-inf/classes!/templates/
参考:https://stackoverflow.com/questions/43065117/java-io-filenotfoundexception-boot-inf-classes-templates
原始代码从classpath下获取模板路径

String filePath = FreeMarkerUtil.class.getResource("/testng").getPath();
cfg.setDirectoryForTemplateLoading(new File(filePath));

修改后:

cfg.setTemplateLoader(new ClassTemplateLoader(
                    new FreeMarkerUtil().getClass().getClassLoader(), basePackagePath));

其中basePackagePath为相对于classpath的路径,如:changefile/testng

2、打包后controller中找不到thymleaf文件
配置文件中增加:spring.thymeleaf.prefix=classpath:/templates

相关文章

网友评论

      本文标题:6、spring boot报错总结

      本文链接:https://www.haomeiwen.com/subject/fepszxtx.html