2019独角兽企业重金招聘Python工程师标准>>>

参考网页

https://blog.csdn.net/mrczr/article/details/78903468

https://blog.csdn.net/yhl_jxy/article/details/78645010

涉及的技术栈

SpringBoot、MyBatis、Druid。

解决--Druid配置类源代码

import java.sql.SQLException;import java.util.ArrayList;import java.util.List;import javax.sql.DataSource;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.annotation.Value;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.context.annotation.DependsOn;import org.springframework.context.annotation.Primary;import com.alibaba.druid.filter.Filter;import com.alibaba.druid.pool.DruidDataSource;import com.alibaba.druid.wall.WallConfig;import com.alibaba.druid.wall.WallFilter;/**** 描述:如果不使用代码手动初始化DataSource的话,监控界面的SQL监控会没有数据("是spring boot的bug???")** @author chhliu 创建时间:2017年2月9日 下午10:33:08* @version 1.2.0*/@Configurationpublic class DruidConfiguration {@Value("${spring.datasource.url}")private String dbUrl;@Value("${spring.datasource.username}")private String username;@Value("${spring.datasource.password}")private String password;// @Value("${spring.datasource.driverClassName}")@Value("${spring.datasource.driver-class-name}")private String driverClassName;@Value("${spring.datasource.initialSize}")private int initialSize;@Value("${spring.datasource.minIdle}")private int minIdle;@Value("${spring.datasource.maxActive}")private int maxActive;@Value("${spring.datasource.maxWait}")private int maxWait;@Value("${spring.datasource.timeBetweenEvictionRunsMillis}")private int timeBetweenEvictionRunsMillis;@Value("${spring.datasource.minEvictableIdleTimeMillis}")private int minEvictableIdleTimeMillis;@Value("${spring.datasource.validationQuery}")private String validationQuery;@Value("${spring.datasource.testWhileIdle}")private boolean testWhileIdle;@Value("${spring.datasource.testOnBorrow}")private boolean testOnBorrow;@Value("${spring.datasource.testOnReturn}")private boolean testOnReturn;@Value("${spring.datasource.poolPreparedStatements}")private boolean poolPreparedStatements;@Value("${spring.datasource.maxPoolPreparedStatementPerConnectionSize}")private int maxPoolPreparedStatementPerConnectionSize;@Value("${spring.datasource.filters}")private String filters;@Value("${spring.datasource.connectionProperties}")private String connectionProperties;@Value("${spring.datasource.useGlobalDataSourceStat}")private boolean useGlobalDataSourceStat;@AutowiredWallFilter wallFilter;@Bean// 声明其为Bean实例@Primary// 在同样的DataSource中,首先使用被标注的DataSourcepublic DataSource dataSource() {DruidDataSource datasource = new DruidDataSource();datasource.setUrl(this.dbUrl);datasource.setUsername(username);datasource.setPassword(password);datasource.setDriverClassName(driverClassName);// configurationdatasource.setInitialSize(initialSize);datasource.setMinIdle(minIdle);datasource.setMaxActive(maxActive);datasource.setMaxWait(maxWait);datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);datasource.setValidationQuery(validationQuery);datasource.setTestWhileIdle(testWhileIdle);datasource.setTestOnBorrow(testOnBorrow);datasource.setTestOnReturn(testOnReturn);datasource.setPoolPreparedStatements(poolPreparedStatements);datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);datasource.setUseGlobalDataSourceStat(useGlobalDataSourceStat);try {datasource.setFilters(filters);} catch (SQLException e) {System.err.println("druid configuration initialization filter: "+ e);}datasource.setConnectionProperties(connectionProperties);// filterList<Filter> filterList = new ArrayList<Filter>();//在设置之前先判断是都已经存在WallConfig,如果有,直接将现有的替换掉List<Filter> filters = datasource.getProxyFilters();boolean isExist = false;for(Filter filter:filters){if(filter instanceof WallFilter){((WallFilter)filter).setConfig(wallConfig());isExist = true;}}if(!isExist){filterList.add(wallFilter);datasource.setProxyFilters(filterList);}return datasource;}@Bean(name = "wallFilter")@DependsOn("wallConfig")public WallFilter wallFilter(WallConfig wallConfig) {WallFilter wallFilter = new WallFilter();wallFilter.setConfig(wallConfig);return wallFilter;}@Bean(name = "wallConfig")public WallConfig wallConfig() {WallConfig wallConfig = new WallConfig();wallConfig.setMultiStatementAllow(true);// 允许一次执行多条语句wallConfig.setNoneBaseStatementAllow(true);// 允许一次执行多条语句return wallConfig;}}

重点代码

//在设置之前先判断是都已经存在WallConfig,如果有,直接将现有的替换掉List<Filter> filters = datasource.getProxyFilters();boolean isExist = false;for(Filter filter:filters){if(filter instanceof WallFilter){((WallFilter)filter).setConfig(wallConfig());isExist = true;}}if(!isExist){filterList.add(wallFilter);datasource.setProxyFilters(filterList);}

描述

需要判断WallConfig是否已存在。WallConfig不存在时可直接如下操作:

filterList.add(wallFilter);

datasource.setProxyFilters(filterList);

已存在的情况下则需要替换之前的WallConfig。

转载于:https://my.oschina.net/u/3866531/blog/2209692

multi-statement not allow解决相关推荐

  1. mybatis Invalid bound statement (not found) 解决

    问题:我的mapper是从另一个工程直接复制过来的,后面一旦调用mapper中的方法,就报错 Invalid bound statement (not found) 解决过程: 1.首先检测映射是否正 ...

  2. IDEA+Maven+Springboot:invalid bound statement (not found) 解决办法

    自己使用Springboot搭建web项目,之前都是使用注解形式来执行sql获取查询内容,这次本承着闲得无聊试一试的想法,突发奇想想用xml的方式执行sql.很走心的参照自己之前spring项目的书写 ...

  3. Maven项目mybatis Invalid bound statement (not found)解决方法

    最近因为工作需要,要学习mybatis框架.在添加好一些依赖之后,通过mybatis进行数据库的crud操作.但是在测试的时候总是报mybatis:Invalid bound statement (n ...

  4. Invalid bound statement (not found)解决办法

    访问后后台报错: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.htu.pr ...

  5. Invalid bound statement (not found)解决

    出现这个错误的原因是,mapper没有和mapper.xml文件映射起来 这里可以检查一下xml文件标签的id是不是和mapper文件中对应的方法名是一致的. 还有看看xml文件中namespace是 ...

  6. #268: declaration may not appear after executable statement in block 解决方法

    这句话翻译过来就是 #268:声明不能出现在块中的可执行语句之后 我们平时在其他文件下使用全局变量,需要用extern来声明全局变量. extern声明全局变量需要在可执行语句之前.把图中这句声明放到 ...

  7. 百分百解决 mbatis/mp报错 Invalid bound statement (not found)

    背景:我用的mp ,使用baseMapper调用封装好的方法都可以使用,所有类型的wrapper都正常使用,但是自己写方法执行复杂的sql就出现错误! 报错信息如下: org.apache.ibati ...

  8. 【Spring+Mybatis】 Invalid bound statement (not found): com.xxxx.mapper.UserMapper.selectUser

    org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.xxxx.mapper.Use ...

  9. 解决Warning: Incorrect string value: '\xD6\xD0\xB9\xFA\xB1\xEA...' for column 'VARIABLE_VALUE'

    目录 项目背景:Python Flask 构建微电影视频网站(MySQL) 报错如下: 分析解决: 1.查看MySQL报错提示 2. 解决问题 项目背景:Python Flask 构建微电影视频网站( ...

  10. mysql aa复制_MySQL的复制架构与优化

    MySQL的复制架构与优化 ###########原理########### 1.主服务器将更新的数据的sql语句(例如,insert,update,delete等)写入到 二进制文件中(由log-b ...

最新文章

  1. 从0梳理1场时间序列赛事!
  2. 大咖云集!Kubernetes and Cloud Native Meetup 深圳站开始报名!
  3. 目标检测(R-CNN、Fast R-CNN、Fater R-CNN)
  4. [BTS]BizTalk2006 SqlAdapter UpdateGram的Update用法
  5. linux-路径的切换-文件的增删拷-目录的增删拷
  6. tornado异步请求响应速度的实例测试
  7. 线上问题排查命令----Shell篇
  8. Synchronized的底层实现原理(看这篇就够了)
  9. ASP.NET 首页性能的4大做法
  10. python构建带数字的古诗词数据集
  11. SSIM(结构相似性)-数学公式及python实现
  12. 2021-10-19 资源收藏
  13. 植被覆盖度的遥感估算
  14. 电脑操作技巧:如何抓图
  15. ESP32/ESP32S2直连腾讯云,实现微信小程序控制
  16. 2022---hgame第一周WriteUp
  17. win32 API函数大全
  18. 苹果id账号密码忘记了怎么办?分享官方教程,快速重置!
  19. Linux网络管理员实用教程
  20. 使用python连接mysql和发送post请求

热门文章

  1. 全球及中国教育行业投资动态与发展决策建议报告2022版
  2. 中国半光纸市场供需形势分析及运行环境研究报告2021年版
  3. 【转载】一个男人关心的东西 决定了他的层次
  4. Zjoi2010排列计数Perm
  5. @总结 - 4@ 多项式的多点求值与快速插值
  6. Unity3d 控制物体移动、旋转、缩放
  7. HTML-参考手册: URL 编码
  8. Windows下及Mac下的IntelliJ IDEA快捷键
  9. 第三百一十节,Django框架,模板语言
  10. golang 编写的邮件客户端