2013-04-17 103 views
1

如何在與Spring集成時正確配置飛路?我看到有一個配置方法需要屬性,但是從Spring XML開始,它需要一個setter方法來提供一種注入Properties實例的方法。飛行路線與彈簧一體化

我可以編寫我自己的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 $ {}屬性替換並使用內置的mechs加載屬性文件,但這會使這些屬性對所有bean都可用,並且我會添加每個需要的屬性。

我的包裝將提供一個二傳手,所以我可以添加以下到我的Spring XML配置:

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

知道的任何想法。

回答

1

或者,您可以使用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')"); 
    } 
}