Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception (已解决)
后端:springboot mybatis
异常:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: com.baomidou.dynamic.datasource.exception.CannotFindDataSourceException: dynamic-datasource can not find primary datasource
### The error may exist in file [C:\resource\MyJava\test\day91\target\classes\mapper\ProductCategoryMapper.xml]
### The error may involve com.hopu.dao.ProductCategoryMapper.getList
### The error occurred while executing a query
### Cause: com.baomidou.dynamic.datasource.exception.CannotFindDataSourceException: dynamic-datasource can not find primary datasource] with root cause
com.baomidou.dynamic.datasource.exception.CannotFindDataSourceException: dynamic-datasource can not find primary datasource
at com.baomidou.dynamic.datasource.DynamicRoutingDataSource.determinePrimaryDataSource(DynamicRoutingDataSource.java:90) ~[dynamic-datasource-spring-boot-starter-3.4.1.jar:3.4.1]
解决方案(注解原因)
1.controller层没有加@ResponseBody
2.Service层实现类未添加注解@Autowired
3.@RestController使用成了@Controller
全网基本上都是这种解决方案,这种解决方案其他博主说有详细说明
这种错误如果都试过了还是报异常,这个也是我经常犯的错误
解决方案(依赖原因)
那必然是jar包多导了,springboot、mybatis的机制就是这样多导包了没用到就会出现这种问题。
比如:
个人人建议去根据搜索一下每个依赖包的含义 或者一个一个删慢慢试
三,解决方案(实体类原因,概率很小)
还有一种也可能包这种异常就是实体类写错了,当然概率很小但是也有可能
建议:可以用 Postman跑跑看这样解决速度会有很大提升文章来源:https://www.toymoban.com/news/detail-413223.html
体类写错了,当然概率很小但是也有可能文章来源地址https://www.toymoban.com/news/detail-413223.html
到了这里,关于Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception (已解决)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!