解题思路:
1. 代码报错,引起异常操作是批量更新,定义如下与Druid有关Bean:
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="driverClassName" value="${db.driverClassName}"/>
<property name="url" value="${db.url}"/>
<property name="username" value="${db.username}"/>
<property name="password" value="${db.passwrod}"/>
<property name="initialSize" value="3"/>
<property name="minIdle" value="3"/>
<property name="maxActive" value="20"/>
<property name="maxWait" value="60000"/>
<property name="filters" value="stat,wall"/>
</bean>
<bean id="stat-filter" class="com.alibaba.druid.filter.stat.StatFilter">
<property name="slowSqlMillis" value="30000"/>
<property name="logSlowSql" value="true"/>
<property name="mergeSql" value="true"/>
</bean>
<bean id="wall-filter" class="com.alibaba.druid.wall.WallFilter">
<property name="dbType" value="mysql"/>
</bean>
2. 浏览了第一篇博客,哦,原来是没有定义,WallConfig ,以及allowMultiQueries=true,随后加之。(使用SpringBoot的哥们应该就可解决此问题了。(纯属猜测))
<bean id="wall-filter" class="com.alibaba.druid.wall.WallFilter">
<property name="dbType" value="mysql"/>
<property name="config" ref="wall-config"/>
</bean>
<bean id="wall-config" class="com.alibaba.druid.wall.WallConfig">
<!-- 批量sql -->
<property name="multiStatementAllow" value="true"/>
</bean>
3. 然后继续报错,阅过N篇博客后,发现第二篇与第三篇博客有异曲同工之处,两者都设置了一个叫proxyFilters的属性,第二篇博客中其实是覆盖掉Druid中原有的proxyFilters,经研究,dataSoruce中filters(stat,wall),其实并不是我们自己定义的Bean(其实他妈还是自己对框架不够了解),而是默认生成的,这个默认生成是从proxyFilters中获取的,所以我们设置的multiStatementAllow没有任何卵用,结合第三篇,就是将我们自己的stat,wall注入了proxyFilters。
<property name="filters" value="stat,wall"/>
<!-- druid -->
<bean id="stat-filter" class="com.alibaba.druid.filter.stat.StatFilter">
<property name="slowSqlMillis" value="30000"/>
<property name="logSlowSql" value="true"/>
<property name="mergeSql" value="true"/>
</bean>
<bean id="wall-filter" class="com.alibaba.druid.wall.WallFilter">
<property name="dbType" value="mysql"/>
<property name="config" ref="wall-config"/>
</bean>
<bean id="wall-config" class="com.alibaba.druid.wall.WallConfig">
<!-- 批量sql -->
<property name="multiStatementAllow" value="true"/>
</bean>
4. 最终Druid相关配置(proxyFilters一定要放在filters上面,filters初始化时没有proxyFilters,就会自己生成默认的,就会导致我们的proxyFilters注入失败,请参考第二篇博客):
<!-- druid -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="driverClassName" value="${db.driverClassName}"/>
<property name="url" value="${db.url}"/>
<property name="username" value="${db.username}"/>
<property name="password" value="${db.passwrod}"/>
<property name="initialSize" value="3"/>
<property name="minIdle" value="3"/>
<property name="maxActive" value="20"/>
<property name="maxWait" value="60000"/>
<property name="proxyFilters">
<list>
<ref bean="stat-filter"/>
<ref bean="wall-filter"/>
</list>
</property>
<property name="filters" value="stat,wall,slf4j"/>
</bean>
<bean id="stat-filter" class="com.alibaba.druid.filter.stat.StatFilter">
<property name="slowSqlMillis" value="30000"/>
<property name="logSlowSql" value="true"/>
<property name="mergeSql" value="true"/>
</bean>
<bean id="wall-filter" class="com.alibaba.druid.wall.WallFilter">
<property name="dbType" value="mysql"/>
<property name="config" ref="wall-config"/>
</bean>
<bean id="wall-config" class="com.alibaba.druid.wall.WallConfig">
<!-- 批量sql -->
<property name="multiStatementAllow" value="true"/>
</bean>
5. 最后不要忘了:allowMultiQueries=true(写在数据库连接串后边的东西。)