2015-10-20 53 views
2

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

<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>  

但是,即使我使用这个application.properties中在XML配置其他占位符的文件,我得到这个错误:

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

+0

您使用的是什么版本的弹簧? – leeor

+0

我们正在使用4.0.2 – tblank

回答

2

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

查看详情post

+0

这看起来很有趣,我会检查出来,谢谢。 – tblank

相关问题