Spring 2.5を使用していたので、プロパティが環境から提供されるか、config_path=C:/application.properties
クラスパスであるデフォルトの場所からオーバーライドされるようにする必要があります。
したがって、以下のように適用しましたapplicationcontext.xml
<bean class="com.test.utils.ExtendedPropertySourcesPlaceholderConfigurer">
<property name="overridingSource" value="file:${config_path}/application.properties"/>
<property name="locations" value="classpath*:META-INF/*-config.properties" />
</bean>
ExtendedPropertySourcesPlaceholderConfigurerコード
public class ExtendedPropertySourcesPlaceholderConfigurer extends PropertySourcesPlaceholderConfigurer implements InitializingBean, ApplicationContextAware {
private ApplicationContext applicationContext;
private Resource overridingSource;
public void setOverridingSource(Resource overridingSource) {
this.overridingSource = overridingSource;
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
@Override
public void afterPropertiesSet() throws Exception {
MutablePropertySources sources = ((ConfigurableApplicationContext) applicationContext).getEnvironment().getPropertySources();
if (overridingSource == null) {
return;
}
sources.addFirst(new ResourcePropertySource(overridingSource));
}
}
今、これを春の3.1.2に移行しています。天気の春は、より効率的な方法でそれを行うための新しいAPIを提供していますか?