1,问题

本人启动spring boot项目后,访问接口,报错信息如下:

{"timestamp": 1537234637805,"status": 500,"error": "Internal Server Error","exception": "javax.servlet.ServletException","message": "Could not resolve view with name 'api/company/info' in servlet with name 'dispatcherServlet'","path": "/api/company/info"
}

2,原因

因为返回信息为json对象,本人在controller方法所在的入口类上,添加的注解为:@Controller

而@Controller是不适合返回json内容的

3,解决方法

方法一:不影响其它方法的使用的情况下,将@Controller注解改为@RestController

方法二:在需要请求的返回json对象的方法上添加@ResponseBody注解

本人项目中该方法所在类的其它方法有的返回到指定页面,所以不能用@RestController直接替换@Controller,所以采用方法二解决了问题。

@Controller与@RestController区别如下

@RestController is a stereotype annotation that combines @ResponseBody and @Controller.
意思是:
@RestController注解相当于@ResponseBody + @Controller合在一起的作用。

1)如果只是使用@RestController注解Controller,则Controller中的方法无法返回jsp页面,配置的视图解析器InternalResourceViewResolver不起作用,返回的内容就是Return 里的内容。

例如:本来应该到success.jsp页面的,则其显示success.

2)如果需要返回到指定页面,则需要用 @Controller配合视图解析器InternalResourceViewResolver才行。
3)如果需要返回JSON,XML或自定义mediaType内容到页面,则需要在对应的方法上加上@ResponseBody注解。

Could not resolve view with name 'xxx' in servlet with name 'dispatcherServlet',相关推荐

  1. Spring Boot问题之JSP无法显示Could not resolve view with name ‘xxxx‘ in servlet with name ‘dispatcherServlet

    问题: 在Spring Boot应用中JSP页面无法显示, 页面提示: 控制台的错误信息类似: javax.servlet.ServletException: Could not resolve vi ...

  2. 解决控制台Could not resolve view with name ...

    关于 Could not resolve view with name 'xxx' in servlet with name 'spring-mvc' 的解决方法 1.原因之一,没有写"@R ...

  3. javax.servlet.ServletException: Could not resolve view with name ‘***‘ in servlet

    javax.servlet.ServletException: Could not resolve view with name 'employee/login' in servlet with na ...

  4. javax.servlet.ServletException: Could not resolve view with name 'destination/isOtherExist' in servl

    五月 28, 2016 5:36:38 下午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() fo ...

  5. Could not resolve view with name '/xx.html' in servlet with name 'dispatcherServlet'

    springboot 项目启动后访问网页,控制台报错: Could not resolve view with name '/xx.html' in servlet with name 'dispat ...

  6. IllegalStateException: Could not resolve view with name

    最近遇到一个重定向的问题困扰了很久,百度也找不到合适的解决方案!! 一 .问题描述 使用的技术:springboot(2.6.x) + springcloud gateway(3.1.x): 1.请求 ...

  7. 造成javax.servlet.ServletException: Could not resolve view with name的各种原因及解决方法

    报错完成信息: javax.servlet.ServletException: Could not resolve view with name '/lose/index' in servlet wi ...

  8. Could not resolve view with name ‘updatelog/saveDetail’

    Could not resolve view with name 'updatelog/saveDetail' in servlet with name 'dispatcherServlet'异常 数 ...

  9. 解决module not found: error: can‘t resolve ‘path‘ in ‘C:\xxx\xxx‘

    控制台报错 解决办法 根据提示有两条解决路径: 方法一:在vue.config.js里module.exports中配置 configureWebpack: {resolve: {fallback: ...

最新文章

  1. 年薪75万的真实技术面试实践攻略(篇章一)
  2. 南方科技大学唐圆圆组招聘环境相关领域科研人才(年薪33~50万)
  3. 计算机教案制作电子表格,人教版七年级信息技术上册《制作电子表格》教案
  4. linux如何扩展根分区,linux扩展根分区详细步骤
  5. LUA ipairs遍历的问题
  6. 在java中图片随机播放_如何在Java中随机播放列表
  7. 开发者应警惕的七种糟糕职业规划错误
  8. linux之解决在ubuntu上面打开window文件乱码问题总结
  9. WebSphere Application Server性能调整工具包
  10. testbench文件显示波形_modelsim仿真没有波形或看不到波形的原因及解决方法 - 全文...
  11. 面向未来 “亿”触即发-中科曙光技术创新大会重磅发布多项创新举措与成果...
  12. 内核如何为各种系统调用服务
  13. 拓端tecdat|R 语言绘制功能富集泡泡图
  14. Delphi7中利用定时器和TRzProgressBar去显示进度条
  15. 从浏览器缓存提取媒体文件
  16. DB2中修改表字段类型或者长度
  17. secureCRT查看日志命令
  18. UVa11137 - Ingenuous Cubrency
  19. 补题:HOJ吉林selection B-Bribing Eve(Gym-101174B) (象限极角排序)
  20. [Excel函数] SUM函数 | SUMIF函数 | SUMIFS函数

热门文章

  1. 和北邮的学生相比,差哪儿了
  2. 医疗小程序源码 在线就诊 视频问诊源码 智慧医院源码
  3. 售前工程师炼成记--第一天
  4. 古希腊悲剧《美狄亚》(1)
  5. 2021年怎么用百家号做医疗关键词排名优化
  6. Openstack glance 安装 403错误
  7. ubuntu 18.10安装ssh软件
  8. notepad++ 使用
  9. HTML5和CSS3新特性一览
  10. PHP留言板(实例)