原因:Druid的防火墙配置(WallConfig)中变量multiStatementAllow默认为false;
解决方案:设置Druid的防火墙配置(WallConfig)中变量multiStatementAllow=true,新建DruidDataSource配置类
配置类代码:
@Configuration
public class DataSourceConfig {
@Autowired
WallFilter wallFilter;
@Bean //声明其为Bean实例
@Primary //在同样的DataSource中,首先使用被标注的DataSource
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource dataSource(){
DruidDataSource datasource = new DruidDataSource();
// filter
List<Filter> filters = new ArrayList<>();
filters.add(wallFilter);
datasource.setProxyFilters(filters);
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;
}
}
然后修改sql连接url路径:声明allowMultiQueries=true;参考路径方式:
url: jdbc:mysql://localhost:3306/ies? allowMultiQueries=true&autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=Hongkong
就此,问题解决。