SpringBoot整合MyBatisPlus出错报错记录:Field userMapper in UserServiceImpl required a bean that could not be

报错信息

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2023-06-16T23:25:44.570+08:00 ERROR 15752 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

Field userMapper in com.example.service.impl.UserServiceImpl required a bean of type 'com.example.mapper.UserMapper' that could not be found.

The injection point has the following annotations:
	- @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'com.example.mapper.UserMapper' in your configuration.
  • 没有排除自动配置的情况下,由于Mapper接口代理对象无法创建,导致Service中需要注入该Mapper接口代理Bean对象的属性无法自动注入,最终导致Springboot程序无法启动
    • 排除自动配置:@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
  • 会导致上述错误,是由于:底层SqlSessionFactory对象无法创建,导致Mapper接口代理对象无法创建

解决方法

  • 如果排除了自动配置:@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class}),不要排除自动配置
  • 没有排除自动配置,可以把MyBatisPlus starter版本更换为最新版
    • 此时,使用的SpringBoot版本为3.1.0,MyBatisPlus starter最新版本为3.5.3.1

你可能感兴趣的:(Java,spring,boot,mybatis,spring,mybatisplus,java)