【问题标题】:Flyway and spring integration飞路和弹簧集成
【发布时间】:2014-01-17 14:07:23
【问题描述】:

与 Spring 集成时如何正确配置 flyway?我看到有一个接受属性的配置方法,但是从 spring XML 中它需要一个 setter 方法来提供一种注入属性实例的方法。

我可以编写自己的 Pojo 来将配置委托给 flyway 实例,但不知何故感觉我错过了一些东西。

这是我的配置:

<bean 
  id="flyway" 
  class="com.googlecode.flyway.core.Flyway" 
  init-method="migrate" 
  lazy-init="false"
  depends-on="dataSource"
  >
   <property name="dataSource" ref="dataSource" />
   <property name="locations" value="classpath:/META-INF/migrations" />
</bean>

我想为迁移配置提供一个专用属性文件,如下所述:

https://github.com/flyway/flyway/blob/master/flyway-commandline/src/main/assembly/flyway.properties

javadoc 看到我可以设置大部分属性。我可以使用 spring ${} 属性替换并使用内置机制加载属性文件,但这会使这些属性对所有 bean 都可用,我会添加我需要的每一个。

我的包装器将提供一个设置器,因此我可以将以下内容添加到我的 spring xml 配置中:

<property name="configLocations" value="classpath:/META-INF/flyway.properties" />

任何想法表示赞赏。

【问题讨论】:

    标签: spring flyway


    【解决方案1】:

    Spring 的 MethodInvokingFactoryBean 应该做你想做的事。

    【讨论】:

      【解决方案2】:

      或者,您可以使用 Flyway 的 SpringJdbcMigration 创建基于 JdbcTemplate 的迁移。下面的例子是从Flyway documentation复制过来的:

      import com.googlecode.flyway.core.api.migration.spring.SpringJdbcMigration;
      import org.springframework.jdbc.core.JdbcTemplate;
      
      public class V1_2__Another_user implements SpringJdbcMigration {
      
          @Override
          public void migrate(JdbcTemplate jdbcTemplate) throws Exception {
              jdbcTemplate.execute("INSERT INTO test_user (name) VALUES ('Obelix')");
          }
      }
      

      【讨论】:

        【解决方案3】:

        你应该使用 spring 注释并包装 Flyway 类,然后做任何你想做的事情。例如,配置飞行路线属性。这篇博文可能会给你一个例子http://esofthead.com/migrate-database-highly-change-environment-multiple-versions-management/

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2018-04-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-11-10
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多