mybatisPlus 自定义sqlSessionFactory sql注入器失效 Invalid bound statement (not found): insertBatchSomeColumn
这是重写后的sqlsessionFactory
@Bean("sqlSessionFactory")public SqlSessionFactory sqlSessionFactory() throws Exception {MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();sqlSessionFactory.setDataSource(multipleDataSource(db1(),db2()));sqlSessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:/com/yaogor/multipledatasource/mapper/*.xml"));//添加事物配置(重点)sqlSessionFactory.setTransactionFactory(new MultiDataSourceTransactionFactory());MybatisConfiguration configuration = new MybatisConfiguration();configuration.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class);configuration.setJdbcTypeForNull(JdbcType.NULL);configuration.setMapUnderscoreToCamelCase(true);configuration.setCacheEnabled(false);sqlSessionFactory.setConfiguration(configuration);sqlSessionFactory.setPlugins(new Interceptor[]{ //PerformanceInterceptor(),OptimisticLockerInterceptor()paginationInterceptor(), //添加分页功能});return sqlSessionFactory.getObject();}
这是mybatisPlusAutoConfiguration 的sqlsessionfactory
@ConditionalOnMissingBeanpublic SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {// TODO 使用 MybatisSqlSessionFactoryBean 而不是 SqlSessionFactoryBeanMybatisSqlSessionFactoryBean factory = new MybatisSqlSessionFactoryBean();factory.setDataSource(dataSource);factory.setVfs(SpringBootVFS.class);if (StringUtils.hasText(this.properties.getConfigLocation())) {factory.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation()));}applyConfiguration(factory);if (this.properties.getConfigurationProperties() != null) {factory.setConfigurationProperties(this.properties.getConfigurationProperties());}if (!ObjectUtils.isEmpty(this.interceptors)) {factory.setPlugins(this.interceptors);}if (this.databaseIdProvider != null) {factory.setDatabaseIdProvider(this.databaseIdProvider);}if (StringUtils.hasLength(this.properties.getTypeAliasesPackage())) {factory.setTypeAliasesPackage(this.properties.getTypeAliasesPackage());}if (this.properties.getTypeAliasesSuperType() != null) {factory.setTypeAliasesSuperType(this.properties.getTypeAliasesSuperType());}if (StringUtils.hasLength(this.properties.getTypeHandlersPackage())) {factory.setTypeHandlersPackage(this.properties.getTypeHandlersPackage());}if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations())) {factory.setMapperLocations(this.properties.resolveMapperLocations());}// TODO 自定义枚举包if (StringUtils.hasLength(this.properties.getTypeEnumsPackage())) {factory.setTypeEnumsPackage(this.properties.getTypeEnumsPackage());}// TODO 此处必为非 NULLGlobalConfig globalConfig = this.properties.getGlobalConfig();// TODO 注入填充器if (this.applicationContext.getBeanNamesForType(MetaObjectHandler.class,false, false).length > 0) {MetaObjectHandler metaObjectHandler = this.applicationContext.getBean(MetaObjectHandler.class);globalConfig.setMetaObjectHandler(metaObjectHandler);}// TODO 注入主键生成器if (this.applicationContext.getBeanNamesForType(IKeyGenerator.class, false,false).length > 0) {IKeyGenerator keyGenerator = this.applicationContext.getBean(IKeyGenerator.class);globalConfig.getDbConfig().setKeyGenerator(keyGenerator);}// TODO 注入sql注入器if (this.applicationContext.getBeanNamesForType(ISqlInjector.class, false,false).length > 0) {ISqlInjector iSqlInjector = this.applicationContext.getBean(ISqlInjector.class);globalConfig.setSqlInjector(iSqlInjector);}// TODO 设置 GlobalConfig 到 MybatisSqlSessionFactoryBeanfactory.setGlobalConfig(globalConfig);return factory.getObject();}
缺少了注入sql注入器这一个步骤,要在自己的sqlsessionFactory补充上ISqlInjector 即可解决上诉问题
自定义bean GlobalConfig
@Beanpublic GlobalConfig globalConfig(@Qualifier("easySqlInjector") ISqlInjector easySqlInjector){GlobalConfig globalConfig = new GlobalConfig();globalConfig.setSqlInjector(easySqlInjector);return globalConfig;}
注入到sqlSessionFactory
@Bean("sqlSessionFactory")public SqlSessionFactory sqlSessionFactory(@Qualifier("globalConfig") GlobalConfig globalConfig ) throws Exception {MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();sqlSessionFactory.setDataSource(multipleDataSource(db1(),db2()));sqlSessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:/com/yaogor/multipledatasource/mapper/*.xml"));//添加事物配置(重点)sqlSessionFactory.setTransactionFactory(new MultiDataSourceTransactionFactory());MybatisConfiguration configuration = new MybatisConfiguration();configuration.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class);configuration.setJdbcTypeForNull(JdbcType.NULL);configuration.setMapUnderscoreToCamelCase(true);configuration.setCacheEnabled(false);sqlSessionFactory.setConfiguration(configuration);sqlSessionFactory.setPlugins(new Interceptor[]{ //PerformanceInterceptor(),OptimisticLockerInterceptor()paginationInterceptor(), //添加分页功能});//添加自定义sql注入接口sqlSessionFactory.setGlobalConfig(globalConfig);//添加自定义sql注入接口return sqlSessionFactory.getObject();}
mybatisPlus 自定义sqlSessionFactory sql注入器失效 Invalid bound statement (not found): insertBatchSomeColumn相关推荐
- springboot集成mybati 后又使用mybatisPlus 出现的问题 BindingException:Invalid bound statement
使用mybatisPlus 插件时出现的问题: 因为项目中已有 mybatis 扫描的路径,之后加上了 mybatisplus 插件导致出现以下错误: BindingException:Invalid ...
- 解决动态SQL报错Invalid bound statement (not found): ……
做一个springboot+vue2的项目,用到动态SQL,在postman测试接口的时候,报错500 回到IDEA查看报错信息Invalid bound statement (not found): ...
- MyBatis-Plus - 一篇带你解决自定义 SQL 注入器失效必杀技
问题分析 Invalid bound statement (not found) 如果你看到这一篇,说明你也是遇到这个问题的人(废话),我们在上一篇(MyBatis-Plus - 一篇带你玩转自定义 ...
- mybatis-plus自定义mapper报org.apache.ibatis.binding.BindingException: Invalid bound statement(not found)
今天在springboot的项目中,需要用到自定义的mapper,之前一直使用mybatis-plus自动生成的mapper,一直可以正常使用,今天因为需求需要,自定义了mapper,但是一直报这个错 ...
- Mybatis-plus使用过程中出现Invalid bound statement (not found):com.xxx.xxx.xxxMapper.selectList
使用Mybatis-plus整合Springboot逆向了一下,发现调用BaseMapper自带的查询就没问题, 用自己写的Sql语句查询就会出现Invalid bound statement (no ...
- MP之自定义分页,多表查询带分页带条件(Error evaluating expression ‘ew.customSqlSegment‘.或 Invalid bound statement)
一.问题 前端所需数据: 但成绩表中只有考生的id及试卷的id,此时就需要进行多表查询,通过考生的id获取姓名字段,通过试卷的id获取试卷名称.分别需要使用到三张表,成绩表,试卷表,考生表.同时需要做 ...
- mybatis-plus的mapper.xml路径配置:Invalid bound statement (not found):...
起初是这样的配置,没什么问题,区别就是平时是resources/mapper/xxxMapper.xml,今天换了resources/mybatis/mapper/xxxMapper,xml 所以在a ...
- mybatis plus报错:Invalid bound statement (not found)
有的同学,在搭建mybatis plus项目时,遇到Invalid bound statement (not found)的问题,实质上是mapper接口和mapper.xml没有映射起来. 这种情况 ...
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):的三种解决方式
在使用mybatis-plus自定义SQL的时候,没有使用注解方式,而是将SQL语句写在mappper.xml文件中,就报了这个错:org.apache.ibatis.binding.BindingE ...
最新文章
- Java将mysql输出csv,如何从Java中的Access数据库导出表并将其保存到.csv
- tensorflow tf.matmul() (多维)矩阵相乘(多维矩阵乘法)
- STM32开发 -- 启动流程
- 使用snmp4j实现Snmp功能(三)
- sqlserver获取当前时间_c#获取并显示当前日期时间
- Python导函数的一些相关
- Hadoop不同版本数据传输distcp问题设置
- Windows 8 Metro中文件的操作及访问(读写删除复制)
- 在Pyramid中使用Mako模板以及默认和.html后缀关联
- sap 消耗策略999_SAP 计划策略测试一
- python多条件判断筛选数据_Python实现多条件筛选目标数据功能【测试可用】
- Golang 正则表达式判断手机号或身份证
- gitee注册新用户收不到验证码, 不管是手机还是邮箱都收不到验证码解决方案
- DNA序列存储为tfr文件并读取
- 软件工程-网上商城分析设计(小组项目)
- 完整的连接器设计手册_TCPP01M12解决USB TypeC 连接器设计6大难题
- SAP接口 财务凭证集成_费用报销
- BMPFont使用教程--免费的位图字体制作工具
- Fluent UDF中调用变量的梯度及其注意点
- 制作FreeCAD安装包的方法
热门文章
- java URLEncoder转码
- 华为运营商级路由器配置示例 | 配置OptionA方式跨域BGP AD VPLS示例
- php 修改文件访问时间,PHP获取文件创建日期、修改日期、访问时间
- Android CPU 双核,双核到底强在哪?四大手机处理器终极横评
- numpy的文件存储 .npy .npz 文件
- 网站二次开发模板源码下载
- Web前端课程大酬宾啦.....
- 标准字头密码体制c语言,密码 实验1 打印
- android 车牌键盘,支持新能源,警车,军车,领事馆车,特种车辆(源代码)
- 联盟广告回利模式4种