占位符替换不使用flyway测试扩展

时间:2012-10-11 10:30:06

标签: flyway

我正在尝试使用flyway测试扩展1.7.0的占位符。   我在flyway.properties中定义了一个占位符:

  flyway.placeholders.schema_name=MYSCHEMA

我的sql脚本看起来像这样:

  create schema ${schema_name};

运行flyway测试时,我收到以下错误:

117157 [main] DEBUG com.googlecode.flyway.core.migration.sql.SqlScript  - Found statement at line 1: create schema ${schema_name};
117157 [main] DEBUG com.googlecode.flyway.core.migration.sql.SqlStatement  - Executing SQL: create schema ${schema_name}
117157 [main] ERROR com.googlecode.flyway.core.migration.DbMigrator  - com.googlecode.flyway.core.exception.FlywayException: Error executing statement at line 1: create schema ${schema_name}
117158 [main] ERROR com.googlecode.flyway.core.migration.DbMigrator  - Caused by org.hsqldb.HsqlException: Unknown JDBC escape sequence: {: {schema_name}
117158 [main] DEBUG com.googlecode.flyway.core.migration.DbMigrator  - Finished migrating to version 1.1 (execution time 00:00.005s)

所以看起来占位符替换不起作用。 顺便说一下,我的flyway.properties文件已成功加载(我也将它用于其他值,如jdbc url)。

有人知道这可能是什么问题吗?

EDIT1 看起来没有调用Flyway类中的configure方法。我是否必须在应用程序上下文中添加内容?

EDIT2 我们找到的一个解决方案是在applicationcontext中设置占位符:

<bean id="flyway" class="com.googlecode.flyway.core.Flyway"
    depends-on="dataSourceRef">
    <property name="dataSource" ref="dataSourceRef" />
    <property name="placeholders" >
      <map>
        <entry key="schema_name" value="${flyway.placeholders.schema_name}" />
     </map> 
    </property>
</bean>

但我们仍在寻找更好的解决方案......

1 个答案:

答案 0 :(得分:0)

抱歉迟到了。我今天第一次看到了你的问题。

我接受了您的问题,另请参阅http://code.google.com/p/flyway-test-extensions/issues/detail?id=14

默认实现和示例不显示它如何工作或提供足够的实用程序来解决它。

解决方案只能通过spring部分完成,取决于flyway-test-extensions的实现。

a。)解决方案的第一部分

它不是一个完整的解决方案,因为 flyway.placeholders。的替换将通过方法 configure 在Flyway中完成,并且我们无法调用。

将以下内容放入您的应用程序上下文中

<!-- also need this as additional include part  -->

xmlns:util="http : //www.springframework.org/schema/util"
xsi:schemaLocation="
    http: // www.springframework.org/schema/util 
    http: // www.springframework.org/schema/util/spring-util-3.0.xsd

<!-- also need this as additional include part --> xmlns:util="http : //www.springframework.org/schema/util" xsi:schemaLocation=" http: // www.springframework.org/schema/util http: // www.springframework.org/schema/util/spring-util-3.0.xsd

<!-- flyway part -->
<util:properties id="flyway.prop" location="/flyway.properties"/>

<bean id="flyway" class="com.googlecode.flyway.core.Flyway" depends-on="dataSourceRef">
    <property name="dataSource" ref="dataSourceRef"/>
    <property name="placeholders" ref="flyway.prop"/>
</bean>

但是在flyway.properties文件中,您必须从属性定义中删除 flyway.placeholders。。我认为这不是完整的通用解决方案。

b。)第二部分

修改

更好的解决方案使用来自当前flyway-test-extension开发的checkin。(http://code.google.com/p/flyway-test-extensions/source/detail?r=921f44bb206527db88f4b59faaf7ea968a743233

  • FlywayHelperFactory.java作为Flyway的工厂实现。将此作为测试源的一部分。
    这也适用于1.7版本。
  • flywayPropertiesContext.xml作为新的应用程序上下文。将它作为测试/资源放在一个名为context的目录中。
    这包含两个示例解决方案如何加载flyway.properties。
    注意:
    本上下文不使用jdbc.properties变量,而是使用flyway属性!
    此上下文也应与flyway-test-extension 1.7.0一起使用
  • 更改您的测试设置并使用<!-- flyway part --> <util:properties id="flyway.prop" location="/flyway.properties"/> <bean id="flyway" class="com.googlecode.flyway.core.Flyway" depends-on="dataSourceRef"> <property name="dataSource" ref="dataSourceRef"/> <property name="placeholders" ref="flyway.prop"/> </bean> 作为新配置。

弗洛里安

相关问题