问题描述:

  Spring Boot 项目访问resources/templates下静态资源文件报500错误,如果页面显示404错误一定是你地址写错了。

报错内容:

Servlet.service() for servlet [dispatcherServlet] in context with path [/test] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template [login], template might not exist or might not be accessible by any of the configured Template Resolvers] with root causeorg.thymeleaf.exceptions.TemplateInputException: Error resolving template [login], template might not exist or might not be accessible by any of the configured Template Resolvers

问题分析:

  SpringBoot项目中resources/templates下的静态资源是不能直接访问的,原因是没有开放访问权限的,因为templates下可能存放有后台管理的页面资源,当templates对外开放就会产生安全隐患,所以templates下的资源需要通过ViewResolver(视图解析器)去解析访问

注意

  1. 这里需要使用@Controller,不能使用@RestController,不然会以Json格式响应到页面,不会进行视图解析。
  2. 如果application.properties文件配置了二级目录请求地址不需要带上此路径return也不需要返回出去。
  3. 如果你的静态资源(列如:login.html)放在templates下的一个目录下(列如:pages)则请求地址需要带上也需要return出去。

案例

我这个项目设置了二级目录:server.servlet.context-path=/test
浏览器访问地址:http://localhost:9999/test/pages/login

@Controller
public class PagesController {// 方法1:@RequestMapping("{pages}/{login}")public String pages(@PathVariable String pages,@PathVariable String login){return pages+"/"+login;}//方法二/*@RequestMapping("pages/login")public String pages(){return "pages/login";}*/
}


了解Spring MVC 执行流程请点击

解决:template might not exist or might not be accessible by any of the configured Template Resolvers报错相关推荐

  1. template might not exist or might not be accessible by any of the configured Template Resolvers

    距离上一篇文章已经很长时间了,最近太忙碌了,今天发布spring boot遇到一个问题,找了好久才找到解决办法,今天贴出来和大家一起分享下,首先看错误信息 1 HTTP Status 500 - Re ...

  2. 【若依(ruoyi)】template might not exist or might not be accessible by any of the configured Template Res

    前言 ruoyi 4.6.0 错误 10:15:11.186 [http-nio-8043-exec-15] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - [ ...

  3. Springboot 报错 template might not exist or might not be accessible by any of the configured Template

    template might not exist or might not be accessible by any of the configured Template Resolvers 1. 搜 ...

  4. template might not exist or might not be accessible by any of the configured

    我在后台返回json串,但是在前台进行接收的时候,出现thymeleaf无法解析,前台接收不到后台传来的信息.所以前台报500. 问题解决:将@Controller更改为@RestController ...

  5. SpringBoot(二)Error resolving template “xxx”, template might not exist or might not be accessible解决办法

    SpringBoot 7 SpringBoot整合持久层技术 7.1 整合JDBC 7.1.1 修改pom文件 <?xml version="1.0" encoding=&q ...

  6. 解决:Error resolving template [/xxx], template might not exist or might not be accessible by any of th

    问题描述 Error resolving template [/xxx], template might not exist or might not be accessible by any of ...

  7. 异常:Error resolving template xxx, template might not exist or might not be accessible...解决办法

    简单表述:控制台出现了这个异常:Error resolving template "xxx", template might not exist or might not be a ...

  8. 解决Error resolving template [x] template might not exist or might not be accessible by any of the con

    文章目录 1. 复现问题 2. 分析问题 2.1 检查pom依赖 2.2 详解thymeleaf引擎 2.2 检查yml配置 3. 解决问题 1. 复现问题 今天配置好shiro + jwt后,可以正 ...

  9. Error resolving template [], template might not exist or might not be accessible by any of the conf

    一.问题: Error resolving template [/index], template might not exist or might not be accessible by any ...

最新文章

  1. leetcode--字符串转换为整数--python
  2. 页面 table 可编辑的实现
  3. 【转】C++ Vector(向量容器)
  4. AngularJS(1)——入门学习
  5. 前端学习(1152):let经典面试题2
  6. 一款问答APP的产品需求文档(PRD)
  7. mysql 的节点组是什么_什么是MySQL集群
  8. 基础算法 —— 高精度计算 —— 高精度加法
  9. TortoiseGit的安装使用
  10. Ubuntu 16.04安装录屏软件SimpleScreenRecorder
  11. java jndi tomcat_tomcat下jndi的三种配置方式
  12. J2SE:Java环境搭建探究环境变量
  13. *与**在python中的使用
  14. 一文读懂机器学习、数据科学、人工智能、深度学习和统计学之间的区别
  15. 专访雷水果国:离1.5K至18K 一个程序猿5每年的成长之路
  16. easypr4android,车牌识别系统EasyPR的批量识别功能测试界面
  17. cmd 新增dns_cmd修改DNS,以及DNS大全
  18. java 佛祖保佑_佛祖保佑 永无bug 注释模板设置详解(仅供娱乐)
  19. 河南漯河警方承认交警代司机交罚款有错-罚款-交警罚款
  20. Java移位运算符详解实例——左移位运算符、带符号的右移位运算符

热门文章

  1. SpringBoot+Vue实现第三方QQ登录(一)
  2. 基于Python实现中文文本关键词抽取的三种方法 课程报告+项目源码及数据
  3. 一个桔子功效等同五味药
  4. 美国诚实签经验——IMG全球医疗险,TODO
  5. 微信幸运大转盘 刮刮卡
  6. 装修公司预约微信小程序源码
  7. 将EMF文件转换成JPG文件
  8. WMI查看远程服务器进程
  9. 单片机at89c51连接ds18b20单片机用c语言怎么编写,求温度传感器DS18b20与单片机at89c51连接,汇编程序?...
  10. TypeScript中的“as const”是什么意思?类型断言!