根据http://docs.spring.io/spring-boot/docs/current/reference/html/howto-properties-and-configuration.html我可以使用 application-${profile}.properties 加载不同的 application.properties 文件并设置活动配置文件。如果 application.properties 发生变化,那就太好了,但是如果我需要使用它的 batch.properties 怎么办?如果我有多个活动档案怎么办?例如:
spring.active.profile=oracle,hornetq,redis
我的属性是使用加载的:
<bean id="placeholderProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
depends-on="datasourceProperty">
<property name="locations" ref="propLocations" />
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreResourceNotFound" value="true" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="order" value="1" />
</bean>
<util:list id="propLocations">
<value>classpath:batch-default.properties</value>
<value>classpath*:batch-${profile}.properties</value>
</util:list>
我假设 batch-${profile}.properties 会尝试查找具有任何活动配置文件的所有属性文件,因此 batch-oracle.properties、batch-redis.properties、batch-hornetq.properties
它找到的将使用,而未找到的将被忽略。然而,情况似乎并非如此,并且根本找不到 ${profile}。
如果我只有一个活动配置文件很好,我可以使用 ${spring.active.profile},但是当我组件化我的应用程序时我正在慢慢创建更多配置文件,我想使用配置文件来加载属性而不创建一堆配置文件特定的属性占位符 bean。
----- 更新 ----- 根据“M. Deinum”的评论,我尝试了以下方法:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes={BatchBootApplication.class})
@WebIntegrationTest(value={"spring.config.name=application,batch"})
@ActiveProfiles("hsql")
public class BatchBootApplicationTest {
@Test
public void testAppContextLoads() {
}
}
我看到了属性文件。