您的位置:首页 > 其它

flyway初始化脚本存在默认特殊字符的问题处理

2015-12-15 11:13 381 查看
一、问题描述

在用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}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: