当前使用版本(必填,否则不予处理)

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.2</version>
        </dependency>

该问题是如何引起的?(确定最新版也有问题再提!!!)

经验证,使用MyBatis-Plus-3.5.2版本(SpringBoot 3.1.6),在application.yml中配置的mybatis-plus.mapper-locations: classpath*:mapper/*.xml无效。必须使用MyBatis的mybatis.mapper-locations才可以生效。 此现象与demo中配置不一致:mybatis-plus-sample-resultmap

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

重现步骤(如果有就写完整)

  1. pom.xml xml <dependencyManagement> <dependencies> <dependency> <!-- Import dependency management from Spring Boot --> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>3.1.6</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>3.0.2</version> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.5.2</version> </dependency> </dependencies>
  2. application.yml yml #mybatis: # type-aliases-package: org.example.sb_chapter_07.mybatis.entity # mapper-locations: # - classpath*:mybatis/mapper/*.xml # - classpath*:mybatis-plus/mapper/*.xml mybatis-plus: type-aliases-package: org.example.sb_chapter_07.mybatis.entity mapper-locations: - classpath*:mapper/*.xml - classpath*:mybatis-plus/mapper/*.xml

报错信息

Caused by: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): org.example.xxx.mybatis.mapper.CityMapper.selectById

注:这里加mybatis-spring-boot-starter的原因是,在不加的时候,会报异常sqlSessionFactory' or 'sqlSessionTemplate' are required

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myBatisPlusCommandLineRunner' defined in file [D:\tmp\DemoSpringBoot\xxx\target\classes\org\example\xxx\runner\MyBatisPlusCommandLineRunner.class]: Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'cityMapper' defined in file [D:\tmp\DemoSpringBoot\xxx\target\classes\org\example\xxx\mybatis\mapper\CityMapper.class]: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

求教

是因为我的配置不正确,还是如上版本导致mybatis-plus的默认配置属性失效?

Comment From: miemieYaho

把你pom里的mybatis-spring-boot-starter去掉,你都会看demo了,demo有这个吗?