Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed;springboot无法注入,注入后无效


错误:Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is com.alibaba.excel.exception.ExcelAnalysisException: java.lang.NullPointerException] with root cause springboot无法注入,注入后无效

控制台报错

页面错误

错误错误原因分析在

在网上找了问题的答案都不能解决,都是讲类的Bean没有注入,
本人的这个错误应该有几个错误情况:

项目背景介绍:springboot+mybatis+easyExcel 操作EXCEL表导入导出

坑一:没有用交给容器管理

解决方法:

1.controller层没有加@ResponseBody

2.Service层(使用dao层)未添加注解@Autowired或者@Resource

3.@RestController使用成了@Controller

4.dao层 添加注解@mapper 或者主启动类@MapperScan("com.wqj.mapper")扫描包

坑二: Spring注解对象 被new后注解被破坏(spring容器内bean不可用(为null,对应bean类里面的注入也会为null))

 问题:Spring注解对象 为什么还要new?

比如你在自定义标签里面需要获得service对象。但是标签对象本身又不能交给spring管理。所以没办法注入。在标签环境里可以拿到servletContext上下文。spring容器实例化后。容器本身就放在这里。你拿出来。把service取出来就可以了。
解决方法:

(通过spring上下文)普通类获取Spring容器中的bean (写工具类调用 )可以参考:https://www.cnblogs.com/s648667069/p/6489557.html

总结:

通过上面的坑,分析自己遇到的问题
1.使用EasyExcel的坑。实际开发中因为读操作中的监听器不能交给spring进行管理,所以不能进行注入实现对数据库的操作
解决方案一:
使用聚合方法,将Service通过有参构造穿进去

解决方案二:坑二的解决方法(本人就是采用的这样的方法)
参考:https://www.jianshu.com/p/164582e580d3


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



猜您在找 Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause ------>Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause 错误:Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] Servlet.service() for servlet [appServlet] in context with path [/item] threw exception [Request processing failed 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.Nul 关于Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause错误提示 Servlet.service() for servlet [dispatcherServlet] in context with path [/heima_ssm_web] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause 报错更改 Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] wit Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception 异常 Spring Cloud ZooKeeper集成Feign的坑2,服务调用了一次后第二次调用就变成了500,错误:Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is com.n
 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM