You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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配置类
    如果项目中存在自定义的FreeMarkerConfigurer Bean,需确保配置了正确的模板加载路径:

    @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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 19:32:03