一、问题描述
在用flyway管理数据库脚本时,脚本中存在insert初始化语句,而insert中value值存在$(**)这种模板数据格式,导致启动时flyway报错,错误信息如下:
二、问题定位
查看org.flywaydb.core.internal.util.PlaceholderReplacer.checkForUnmatchedPlaceholderExpression源码分析:
发现placeholderPrefix和placeholderSuffix默认表达式为:$(和),所以如果脚本中存在此类特殊符就会导致冲突。
/**
* The prefix of every placeholder. Usually ${
*/
private final String placeholderPrefix;
/**
* The suffix of every placeholder. Usually }
*/
private final String placeholderSuffix;
三、解决方法
1、修改默认placeholderPrefix和placeholderSuffix
flyway.setPlaceholderPrefix("#(");
flyway.setPlaceholderSuffix(")");
2、insert table1(c1) value (replace('%{x}','%','$')
用replace 规避了直接写 ${x}