6、spring boot报错总结

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

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容