当前使用版本(必填,否则不予处理)
3.5.4.1
该问题是如何引起的?(确定最新版也有问题再提!!!)
非Spring环境, 使用mybatis-plus时, 如果DAO中有相同的方法名,出现转化异常
重现步骤(如果有就写完整)
报错信息
java.lang.ClassCastException: org.apache.ibatis.session.Configuration$StrictMap$Ambiguity cannot be cast to org.apache.ibatis.mapping.MappedStatement
Comment From: nieqiurong
按工程的方式提交上来.
Comment From: nieqiurong
看了一下,整合的方式就有问题.你先用mybatis原生解析出来所有的再添加至mybatis-plus就没那个必要了,如果非要这么做,只能先把原生解析出来的短key先排除掉再添加进去.
Comment From: nieqiurong
synchronized (SqlSessionFactoryUtils.class){
if(!Objects.equals(Boolean.TRUE, isInitMap.get(key))){
//解析Mybatis的XML
Reader reader = Resources.getResourceAsReader(mybatisXMlPath);
MybatisXMLConfigBuilder xmlConfigBuilder = new MybatisXMLConfigBuilder(reader, environmentName);
//mybatis的Configuration
MybatisConfiguration mybatisConfiguration = (MybatisConfiguration) xmlConfigBuilder.parse();
//mybatis-plus的Configuration
// MybatisConfiguration mybatisPlusConfiguration = new MybatisConfiguration(mybatisConfiguration.getEnvironment());
// mybatisPlusConfiguration.setUseGeneratedShortKey(false);
//注册mybatis-plus的mapper
// mybatisConfiguration
// .getMapperRegistry()
// .getMappers()
// .forEach(mybatisPlusConfiguration::addMapper);
// mybatisConfiguration
// .getMappedStatements()
// .forEach(mappedStatement -> {
// if(!mybatisPlusConfiguration.hasStatement(mappedStatement.getId(), false)){
// mybatisPlusConfiguration.addMappedStatement(mappedStatement);
// }
// });
//添加分页插件
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
mybatisConfiguration.addInterceptor(interceptor);
//mybatis-plus的SqlSessionFactory
SqlSessionFactory sqlSessionFactory = new MybatisSqlSessionFactoryBuilder()
.build(mybatisConfiguration);
isInitMap.put(environmentName, Boolean.TRUE);
sqlSessionFactoryMap.put(key, sqlSessionFactory);
}
}
Comment From: nieqiurong
直接就能转成mybatis-plus需要的,不需要用mybatis原生的解析. MybatisXMLConfigBuilder xmlConfigBuilder = new MybatisXMLConfigBuilder(reader, environmentName);
Comment From: wlg18383355682
好的,谢谢指导,问题解决了