У меня есть файл пружины с именем provider.xml
<context:property-placeholder location="classpath:META-INF/spring
/${build.profile.id}/config.properties" />
У меня есть два разных config.properties, один в META-INF / spring / ws1, а другой в META-INF / spring / ws2
это часть моего pom.xml
<profiles>
<profile>
<id>ws1</id>
<properties>
<build.profile.id>ws1</build.profile.id>
</properties>
</profile>
<profile>
<id>ws2</id>
<properties>
<build.profile.id>ws2</build.profile.id>
</properties>
</profile>
</profiles>
Я получаю эту ошибку:
Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [META-INF/spring/${build.profile.id}/config.properties] cannot be opened because it does not exist
Но если я попытаюсь прочитать его без переменной, вот как это работает:
<context:property-placeholder location="classpath:META-INF/spring/ws1/config.properties" />
как можно прочитать его как переменную в контексте: свойство-заполнитель?
После того, как я добавил этот код в provider.xml
<bean id="propertyPlaceholderConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="searchSystemEnvironment" value="true" />
</bean>
Я получил эту ошибку:
Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'org.springframework.context.support.PropertySourcesPlaceholderConfigurer#0' defined in null: Could not resolve placeholder 'build.profile.id' in value "classpath:META-INF/spring/${build.profile.id}/config.properties"; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'build.profile.id' in value "classpath:META-INF/spring/${build.profile.id}/config.properties"
at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:223)
at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:222)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:86)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:283)