Circular view path///Can't resolve view with name "" in servlet with name dispatcherServlet

在Springboot项目中遇到'Could not resolve view with name 'index' in servlet with name 'dispatcherServlet''的问题,尝试了配置静态资源路径、启用@EnableWebMvc、修改@RequestMapping路径等方法均未解决。最终发现是缺少Thymeleaf的依赖导致,添加Thymeleaf依赖后问题解决。同时提醒注意@RestController和@Controller注解的区别。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

简直愚蠢的错误:搞了我快一个小时,记录以自勉。

  1. 刚开始是出现了:Could not resolve view with name ‘index’ in servlet with name ‘dispatcherServlet’
    有文章说是因为没有配置好静态资源的路径,但是我在application.properties中已经配置了html对应的路径:
#thymeleaf start
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
#spring.thymeleaf.content-type=text/html
#开发时关闭缓存,不然没法看到实时页面
spring.thymeleaf.cache=false
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
#thymeleaf end

但是我还是尝试了网上所说的方式:启动类继承自WebConfigurationSurport,加上@EnableWebMvc注解:
详见:https://blog.youkuaiyun.com/testcs_dn/article/details/80249894

         /**
	 * 配置JSP视图解析器
	 * 如果没有配置视图解析器。Spring会使用BeanNameViewResolver,通过查找ID与逻辑视图名称匹配且实现了View接口的beans
	 * 
	 * @return
	 */
	@Bean
	public InternalResourceViewResolver setupViewResolver() {
		InternalResourceViewResolver resolver = new InternalResourceViewResolver();
		/** 设置视图路径的前缀 */
		resolver.setPrefix("/WEB-INF/jsp/");
		/** 设置视图路径的后缀 */
		resolver.setSuffix(".jsp");
		return resolver;
	}
  1. 然后出现了springmvc的Circular view path的错误:

    javax.servlet.ServletException: Circular view path [login]: would dispatch back to the cu

有解决方案说是:@RequestMapping中的路径和html(或者jsp)文件名不要写成一样的,修改后还是无法解决问题。
还有说在Test类中重新配置一遍视图:https://blog.youkuaiyun.com/wthfeng/article/details/52742830
还有SpringMVC出现该问题的解决方案:https://blog.youkuaiyun.com/cjj1030833228/article/details/50993009

最后,你们知道是什么问题吗???是因为我没有在Pom中引入Thymeleaf的依赖!!简直愚蠢哈哈哈哈哈。

还有注意@RestController和@Controller的区别。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值