当前使用版本(必填,否则不予处理)
3.4.1
该问题是如何引起的?(确定最新版也有问题再提!!!)
手动初始化mybatis plus的SqlSessionFactory 无法加载mapper自定义crud方法,debug发现mapperStatement里只有baseMapper里的crud方法
重现步骤(如果有就写完整)
//省略对应的xml
public interface XxTestMapper extends BaseMapper<XxTest> {
自定义查询,省略对应xml
XxTest customQuery(@Param("name") String name);
}
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mysql://xxx:3306");
dataSource.setUsername("xxx");
dataSource.setPassword("xxx");
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setMinIdle(5);
dataSource.setMaxActive(10);
dataSource.setInitialSize(8);
dataSource.setMaxWait(60000);
dataSource.setTimeBetweenEvictionRunsMillis(60000);
dataSource.setMinEvictableIdleTimeMillis(300000);
dataSource.setValidationQuery("SELECT 1 FROM DUAL");
dataSource.setTestWhileIdle(true);
dataSource.setTestOnBorrow(false);
dataSource.setTestOnReturn(false);
TransactionFactory transactionFactory = new JdbcTransactionFactory();
Environment environment = new Environment("development", transactionFactory, dataSource);
MybatisConfiguration configuration = new MybatisConfiguration(environment);
configuration.addMapper(XxTestMapper.class);
MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSource);
sqlSessionFactoryBean.setConfiguration(configuration);
GlobalConfig globalConfig = new GlobalConfig();
GlobalConfig.DbConfig dbConfig = new GlobalConfig.DbConfig();
dbConfig.setIdType(IdType.AUTO);
globalConfig.setDbConfig(dbConfig);
sqlSessionFactoryBean.setGlobalConfig(globalConfig);
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
paginationInnerInterceptor.setMaxLimit(20000L);
interceptor.addInnerInterceptor(paginationInnerInterceptor);
sqlSessionFactoryBean.setPlugins(interceptor);
SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBean.getObject();
XxTestMapper xxTestMapper = sqlSessionFactory.openSession().getMapper(XxTestMapper.class);
XxTest = xxTestMapper.customQuery("asdfs");
这样手动初始化,找不到自定义的查询,debug发现mapperStatement里只有baseMapper里的crud方法
报错信息
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.mapper.XxTestMapper.customQuery
at org.apache.ibatis.binding.MapperMethod$SqlCommand.
Comment From: miemieYaho
https://github.com/baomidou/mybatis-plus/blob/3.0/mybatis-plus-boot-starter/src/main/java/com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.java