weixin_43562801 2024-08-16 02:06 采纳率: 0%
浏览 32

SpringBoot整合Mybatis-plus8.0.30报错


org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'persistenceExceptionTranslationPostProcessor' defined in class path resource [org/springframework/boot/autoconfigure/dao/PersistenceExceptionTranslationAutoConfiguration.class]: Unsatisfied dependency expressed through method 'persistenceExceptionTranslationPostProcessor' parameter 0: Invalid bean definition with name 'driverInfoMapper' defined in file [E:\workspace\Springsecture-01-test\target\classes\com\xgj\application\mapper\DriverInfoMapper.class]: Invalid value type for attribute 'factoryBeanObjectType': java.lang.String
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:795) ~[spring-beans-6.1.11.jar:6.1.11]
    
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'driverInfoMapper' defined in file [E:\workspace\Springsecture-01-test\target\classes\com\xgj\application\mapper\DriverInfoMapper.class]: Invalid value type for attribute 'factoryBeanObjectType': java.lang.String
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:857) ~[spring-beans-6.1.11.jar:6.1.11]
    at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:663) ~[spring-beans-6.1.11.jar:6.1.11]

使用的是mybatis-plus-boot-starter下3.5.3.2的版本;spring-boot-starter-parent使用的是3.3.2版本报的错;启动类上加了 代码

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@MapperScan("com.xgj.application.mapper")

后面改成下面依赖

  <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-spring-boot3-starter</artifactId>
            <version>3.5.5</version>
        </dependency>

继续报错,还是报如下错(依赖树没有冲突)

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'driverInfoServiceImpl': Unsatisfied dependency expressed through field 'baseMapper': Error creating bean with name 'driverInfoMapper' defined in file [E:\workspace\Springsecture-01-test\target\classes\com\xgj\application\mapper\DriverInfoMapper.class]: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:787) ~[spring-beans-6.1.11.jar:6.1.11]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:767) ~[spring-beans-6.1.11.jar:6.1.11]
  • 写回答

5条回答 默认 最新

  • 一直免费一直爽 2024-08-16 02:07
    关注

    以下回复参考:皆我百晓生券券喵儿等免费微信小程序作答:

    根据您提供的信息,问题可能是由于MyBatis-Plus的版本与Spring Boot的版本不兼容导致的。您可以尝试以下解决方案:

    1. 将MyBatis-Plus的版本升级到与Spring Boot版本兼容的版本。例如,如果您使用的是Spring Boot 3.3.2,您可以尝试使用MyBatis-Plus 3.5.5或更高版本。

    2. 检查您的项目中是否有其他依赖冲突。您可以使用Maven或Gradle的依赖树功能来查看项目的依赖关系。如果有冲突,请尝试解决它们。

    3. 确保您的DriverInfoMapper接口使用了正确的注解。它应该包含@Mapper注解,以便Spring能够识别并自动创建相应的bean。例如:

    import com.baomidou.mybatisplus.core.mapper.BaseMapper;
    import org.apache.ibatis.annotations.Mapper;
    
    @Mapper
    public interface DriverInfoMapper extends BaseMapper<DriverInfo> {
        // Your methods here
    }
    
    1. 如果问题仍然存在,您可以尝试在启动类上添加@EnableTransactionManagement注解,以启用事务管理:
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.transaction.annotation.EnableTransactionManagement;
    
    @SpringBootApplication
    @EnableTransactionManagement
    public class Application {
        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
        }
    }
    

    希望这些建议能帮助您解决问题。如果问题仍然存在,请随时提供更多详细信息,以便我们能够更好地帮助您。

    评论

报告相同问题?

问题事件

  • 修改了问题 8月16日
  • 创建了问题 8月16日

悬赏问题

  • ¥15 如何在vue.config.js中读取到public文件夹下window.APP_CONFIG.API_BASE_URL的值
  • ¥50 浦育平台scratch图形化编程
  • ¥20 求这个的原理图 只要原理图
  • ¥15 vue2项目中,如何配置环境,可以在打完包之后修改请求的服务器地址
  • ¥20 微信的店铺小程序如何修改背景图
  • ¥15 UE5.1局部变量对蓝图不可见
  • ¥15 一共有五道问题关于整数幂的运算还有房间号码 还有网络密码的解答?(语言-python)
  • ¥20 sentry如何捕获上传Android ndk 崩溃
  • ¥15 在做logistic回归模型限制性立方条图时候,不能出完整图的困难
  • ¥15 G0系列单片机HAL库中景园gc9307液晶驱动芯片无法使用硬件SPI+DMA驱动,如何解决?