Flyway DB Upgrader in Spring

2019-08-13 03:58发布

问题:

I've a problem with the Flyway schema upgrader for Spring. Following code exists in my servlet.xml

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost/database"/>
    <property name="username" value="root"/>
    <property name="password" value="password"/>
</bean>

<bean id="flyway" class="com.googlecode.flyway.core.Flyway" init-method="migrate" depends-on="dataSource">
    <property name="dataSource" ref="dataSource"/>
</bean>

But how to set the migration script directory or rather whats the default directory?

回答1:

Everything is explained in the excellent documentation:

If you want to alter the default directory (which is db/migration as shown on the picture above), I believe this should work (see: Flyway.setBaseDir()):

<bean id="flyway" class="com.googlecode.flyway.core.Flyway" init-method="migrate" depends-on="dataSource">
    <property name="dataSource" ref="dataSource"/>
    <property name="baseDir" value="my/migrations/path"/>
</bean>