Spring Boot从1.x升级到2.3.12后找不到spring.ftl求助
解决Spring Boot 2.3.12升级后Freemarker找不到spring.ftl的问题
调整Freemarker配置,允许加载类路径依赖中的模板
在application.properties(或application.yml)中添加或修改以下配置:spring.freemarker.template-loader-path=classpath:/templates/,classpath:/META-INF/resources/templates/ spring.freemarker.prefer-file-system-access=false说明:
prefer-file-system-access设为false后,应用会优先从类路径(包括依赖jar包内的资源)加载模板,而非仅读取本地文件系统的/templates/目录。检查自定义Freemarker配置类
如果项目中存在自定义的FreeMarkerConfigurerBean,需确保配置了正确的模板加载路径:@Bean public FreeMarkerConfigurer freeMarkerConfigurer() { FreeMarkerConfigurer configurer = new FreeMarkerConfigurer(); configurer.setTemplateLoaderPaths("classpath:/templates/", "classpath:/META-INF/resources/templates/"); configurer.setPreferFileSystemAccess(false); return configurer; }确认依赖版本一致性
保证spring-boot-starter-freemarker的版本与Spring Boot 2.3.12完全匹配,避免依赖版本混乱:<!-- Maven依赖示例 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> <version>2.3.12.RELEASE</version> </dependency>清理缓存并重启应用
执行构建工具的clean命令清理缓存,重新打包后启动应用,避免IDE或构建缓存导致的模板加载异常。
内容的提问来源于stack exchange,提问作者JKLee
相关产品推荐
相关产品推荐

