MybatisPlus+Springboot报错 Error creating bean with name ‘xxxMapper‘ defined in file [F:\Java\heig

在搭建项目的时候使用到mybatisplus的generator代码生成器环境搭建,具体请看
springboot2+mybatisplus+redis+generator代码生成器环境搭建
搭建成功以后发现代码报错

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'paymentServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'paymentMapper' defined in file [F:\Java\heightConcurrence\target\classes\com\luguz\mapper\PaymentMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: com/baomidou/mybatisplus/core/incrementer/IdentifierGenerator
	
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'paymentMapper' defined in file [F:\Java\heightConcurrence\target\classes\com\luguz\mapper\PaymentMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: com/baomidou/mybatisplus/core/incrementer/IdentifierGenerator
	
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: com/baomidou/mybatisplus/core/incrementer/IdentifierGenerator
	
Caused by: java.lang.NoClassDefFoundError: com/baomidou/mybatisplus/core/incrementer/IdentifierGenerator

等错误,初步分析是因为生成的maper没有扫描到
查看mapper文件

@Repository
public interface PaymentMapper extends BaseMapper<Payment> {

}

以及启动类的扫描配置

@MapperScan("com.luguz.mapper")

初步分析是没有问题的,查看mapper的位置配置

mybatis-plus:
  mapper-locations: classpath*:mapper/*Mapper.xml

以及生成的target文件,都是正确无误的,最后检查mysql的连接配置也是没有问题,怀疑是pom配置版本问题,查找资料了解到在mybatis-plus 3.0x以下使用分页插件的时候需要添加一个config配置类文件

@Configuration //配置类
@EnableTransactionManagement
@MapperScan("com.luguz.mapper")
public class mybatisPlusConfig {
//配置乐观锁拦截器
//    @Bean
//    public OptimisticLockerInterceptor optimisticLockerInterceptor(){
//        return new OptimisticLockerInterceptor();
//    }

//    分页插件
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
        return paginationInterceptor;
     }

//     逻辑删除
//    @Bean
//    public ISqlInjector sqlInjector() {
//        return new LogicSqlInjector();
//    }

//    sql执行效率优化
//    @Bean
//    @Profile({"dev","test"})
//    public PerformanceInterceptor performanceInterceptor() {
//        PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
//        //格式化sql语句
//        Properties properties = new Properties();
//        properties.setProperty("format", "false");
//        performanceInterceptor.setProperties(properties);
//        return performanceInterceptor;
//    }

}

都检测了一遍发现还行无法解决该问题,最后想起了创建文件的时候默认使用的包名忘记更改了,创建完成以后再更改的包名
重新创建一个项目,重新生成一遍成功启动。

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