通过spring的依赖属性调用flyway会导致无限循环

时间:2017-11-21 07:39:38

标签: java spring flyway

我通过flyway使用spring。在我的xml上下文文件中,我有一些bean定义如下:

<bean id="baseVersion" class="org.flywaydb.core.api.MigrationVersion">
    <constructor-arg index="0" value="${flyway.baseVersion}"/>
</bean>  
<bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">
    <property name="driverClass" value="${database.driverClassName}"/>
    <property name="jdbcUrl" value="${database.url}"/>
    <property name="username" value="${database.username}"/>
    <property name="password" value="${database.password}"/>  
</bean>
<bean id="flyway" class="org.flywaydb.core.Flyway" init-method="migrate" >
            <property name="dataSource" ref="dataSource"/>
            <property name="baselineVersion" ref="baseVersion"/>
            <property name="baselineOnMigrate" value="${flyway.baselineOnMigrate}"/>
            <property name="validateOnMigrate" value="${flyway.validateOnMigrate}"/>
            <property name="ignoreFutureMigrations" value="${flyway.ignoreFutureMigrations}"/>
            <property name="ignoreMissingMigrations" value="${flyway.ignoreMissingMigrations}"/>
            <property name="outOfOrder" value="${flyway.outOfOrder}"/>
            <property name="targetAsString" value="${flyway.targetVersion}"/>
</bean>
<!-- *************************************************************** -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean" depends-on="flyway">
        <property name="annotatedClasses" >
            <list>
                 <value>foo.bar.Entity1</value>
                 ...
            </list>
        </property>
        <property name="dataSource" ref="dataSource"/>
        <property name="mappingResources">
            <list>
                  <value>/hbms/Table1.hbm.xml</value>
                  ....
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${database.dialect}</prop>
                ...
            </props>
        </property>
</bean>

问题是当flyway在迁移时失败时,spring会吞下它的异常并重试一次又一次地调用它......并且无限循环!

2017-11-21 10:07:35,280 [main] INFO  o.f.c.i.dbsupport.DbSupportFactory  - Database: jdbc:oracle:thin:@192.168.99.100:1521:orcl (Oracle 11.2)
2017-11-21 10:07:37,564 [main] INFO  o.f.c.i.dbsupport.DbSupportFactory  - Database: jdbc:oracle:thin:@192.168.99.100:1521:orcl (Oracle 11.2)
2017-11-21 10:07:38,884 [main] INFO  o.f.c.i.dbsupport.DbSupportFactory  - Database: jdbc:oracle:thin:@192.168.99.100:1521:orcl (Oracle 11.2)
2017-11-21 10:07:39,565 [main] INFO  o.f.c.i.dbsupport.DbSupportFactory  - Database: jdbc:oracle:thin:@192.168.99.100:1521:orcl (Oracle 11.2)
2017-11-21 10:07:40,214 [main] INFO  o.f.c.i.dbsupport.DbSupportFactory  - Database: jdbc:oracle:thin:@192.168.99.100:1521:orcl (Oracle 11.2)
...

此问题的一个后果是Oracle在密码错误时锁定用户,因为当FAILED_LOGIN_ATTEMPTS不是LIMITUNLIMITED超过AbstractAutowireCapableBeanFactory值!

我已经跟踪了春天的代码...异常是在recordSuppressedExceptions类的第1760行捕获并继续前进...最后以某种方式被抑制,尽管false是{{1} } DefaultSingletonBeanRegistry类!

spring-beans版本为4.3.11flyway版本为4.2.0
任何解决方案或解决方法?

P.S。当我将日志级别增加到TRACE时,Spring会打印flyway的异常。

UPDATE
Flyway的房产:

#database migration config
flyway.baseVersion=1.0
flyway.baselineOnMigrate=true
flyway.validateOnMigrate=true
flyway.locationsToScan=db/migration
flyway.ignoreFutureMigrations=true
flyway.ignoreMissingMigrations=false
flyway.outOfOrder=false
#taget migration version, i.e. the version up to which the migration is done.
#migrations with a higher version number will be ignored. Default=BigInteger.valueOf(-1)
flyway.targetVersion=9223372036854775807

0 个答案:

没有答案