错误详情
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): cn.com.bofeng.pipihealth.database.mapper.rule.RuleServiceIndicatorsDetailMapper.selectList
报错的原因以及解决方法
mybatis包冲突,导致依赖包使用的不是mybatis plus的包
- 检查是否引入了Mybatis plus依赖
官网中,引入的mybatis plus依赖如下
<!-- spring boot -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
<!-- spring -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>3.5.1</version>
</dependency>
引入 MyBatis-Plus 之后请不要再次引入 MyBatis 以及 MyBatis-Spring,以避免因版本差异导致的问题。
- 删除导致冲突的mybatis其它依赖
检查pom文件中是否引入了其它mybatis的依赖项,如果有以下依赖,可以直接注释掉:
<!-- spring boot -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
<!-- spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.4</version>
</dependency>
sqlSessionFactory不是mybatis plus的SqlSessionFactory
- spring boot中的sqlSessionFactory bean配置
@Configuration
public class MybatisPlusConfig {
@Value("${mybatis.mapper-locations}")
private String mapperLocations;
// spring boot
@Bean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource)
throws Exception {
final MybatisSqlSessionFactoryBean sessionFactory = new MybatisSqlSessionFactoryBean();
sessionFactory.setDataSource(dataSource);
sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapperLocations));
return sessionFactory.getObject();
}
}
- spring boot中的sqlSessionFactory bean配置
<!-- spring -->
<bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:/mybatis.xml"/>
<property name="mapperLocations">
<array>
<value>classpath*:/mapper/**/*.xml</value>
</array>
</property>
</bean>