我应该能够为 Flyway bean 的初始化方法使用 Spring 占位符吗?

Should I be able to use a Spring placeholder for Flyway bean's init-method?

由于我们对不同的构建和部署使用不同的 application.properties 文件(例如,除了部署到 Prod 之外,还针对不同类型的开发人员和测试环境),我希望能够更改在 Spring 的 application-context.xml 中为 Flyway bean 配置了 init-method。我想做这样的事情:

<context:property-placeholder location="classpath:application.properties,classpath:application-instance.properties"/>
<bean id="flyway" class="org.flywaydb.core.Flyway" init-method="${flyway.database.init.method}">
    <property name="baselineOnMigrate" value="true" />
    <property name="locations" value="classpath:/db-migrations/sql/" />
    <property name="dataSource" ref="dataSource" />
</bean>    

但是即使我在 XML 配置中的其他占位符中使用此 application.properties 文件,我也会收到此错误:

.BeanDefinitionValidationException: Couldn't find an init method named '${flyway.database.init.method}' on bean with name 'flyway'

如果您使用的是 spring 3.1 或更高版本,我强烈建议您考虑为此使用环境配置文件。它们是专门为解决这个问题而设计的。

查看此 post 了解详情。