本意是打算写一个Spring Boot 和Mybatis-Plus一起的订单增删改查,
写完感觉哪哪都对,但在运行后,却发现无尽的报错,一长串子,大致关键信息为:
Error creating bean with name 'orderController': Unsatisfied dependency expressed through field 'orderService'
Error creating bean with name 'orderServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'
Error creating bean with name 'orderMapper': Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
等。
就是:
orderController
的 orderService
字段依赖注入失败
orderServiceImpl
的 baseMapper
字段依赖注入失败。
orderMapper
的创建失败
大致就是字段注入不进去,找了好久都没发现症结在哪。
在许久许久以后以后,终于发现了问题:
我的jdk是17的,在前面建项目的时候我又将spring boot 选择了3点多,
引入Mybatis-Plus依赖时又选择了3.4.1,版本太低,所以才不成功,要mybatis-plus 3.5.3 及以上版本才支持 spring boot 3,后经别人建议,下次建立项目时,可以将spring boot的版本往下选选,比如2点几。不用担心jdk的问题,因为jdk是向下兼容的。