报错解决:Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
--------------在开发spring boot项目的时候出现的问题-------------
console报错:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException
如图:
一开始的思路,空指针,可能没有运行到sql语句的问题,检查自己xxxmapper.xml是否写错sql标签语句中的信息,检查完没有错误。然后又用Navicat运行sql语句是没有错误的!!
结果我百度了一下,发现出现这问题的还有两个原因:
-
Service层实现类未添加注解@Autowired
-
controller层没有加@ResponseBody
@Autowired注释:它可以对类成员变量、方法及构造函数进行标注,完成自动装配的工作。==>自动注入依赖的Bean。
然后我自己检查了一下我的代码:
居然没有添加注释@Autowired,我想锤自己了,添加完后就可以了。