title: How to use several property-placeholder in different contexts
body: <p>I use Spring Framework and Spring Security. There are different places where I need to use the page path. For example, &quot;/mainpath&quot;.
  I place it in /WEB-INF/classes/path.properties.
  The path should be used in servlet-context.xml and in security-context.xml.
  If the following is placed in both contexts</p>
  <pre><code>&lt;context:property-placeholder location=&quot;/WEB-INF/classes/path.properties&quot;/&gt;
  </code></pre>
  <p>it will result in</p>
  <pre><code>java.lang.IllegalArgumentException: &quot;Could not resolve placeholder 'main.page' in string value &quot;${main.page}&quot;
  </code></pre>
  <p>The following does not give required result.</p>
  <pre><code>&lt;context:property-placeholder location=&quot;/WEB-INF/classes/path.properties&quot; ignore-unresolvable=&quot;true&quot;/&gt;
  </code></pre>
  <p>UPD.
  path.properties:</p>
  <pre><code>main.page=mainpage
  </code></pre>
  <p>I exclude property-placeholder from servlet-context.xml. The error still arises.
  The part of security-context:</p>
  <pre><code>&lt;context:property-placeholder location=&quot;classpath:/path.properties&quot; 
      ignore-unresolvable=&quot;false&quot;/&gt;
  &lt;http use-expressions=&quot;true&quot;&gt;
      &lt;intercept-url pattern=&quot;/${main.page}&quot; access=&quot;isAuthenticated()&quot; 
      requires-channel=&quot;http&quot;/&gt;
  ...
  &lt;/http&gt;
  </code></pre>
  <p>I tried to place path.properties in different folders.
  Property-placeholder is also used in datasource-tx-jpa.xml with other property file.</p>
  <p>Folders structure:</p>
  <p><img src="https://i.stack.imgur.com/BHPdY.jpg" alt="Folders structure" /></p>
  <p>Stacktrace:</p>
  <pre><code>ERROR: org.springframework.web.context.ContextLoader - Context initialization failed
  org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0' defined in null: Could not resolve placeholder 'main.page' in string value &quot;/${main.page}&quot;; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'main.page' in string value &quot;/${main.page}&quot;
      at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:211)
      at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.processProperties(PropertySourcesPlaceholderConfigurer.java:180)
      at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.postProcessBeanFactory(PropertySourcesPlaceholderConfigurer.java:155)
      at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:265)
      at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:162)
      at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:609)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
      at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
      at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
      at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4720)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5154)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'main.page' in string value &quot;/${main.page}&quot;
      at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:174)
      at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126)
      at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:194)
      at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:158)
      at org.springframework.context.support.PropertySourcesPlaceholderConfigurer$2.resolveStringValue(PropertySourcesPlaceholderConfigurer.java:175)
      at org.springframework.beans.factory.config.BeanDefinitionVisitor.resolveStringValue(BeanDefinitionVisitor.java:282)
      at org.springframework.beans.factory.config.BeanDefinitionVisitor.resolveValue(BeanDefinitionVisitor.java:209)
      at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitIndexedArgumentValues(BeanDefinitionVisitor.java:150)
      at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitBeanDefinition(BeanDefinitionVisitor.java:84)
      at org.springframework.beans.factory.config.BeanDefinitionVisitor.resolveValue(BeanDefinitionVisitor.java:169)
      at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitMap(BeanDefinitionVisitor.java:259)
      at org.springframework.beans.factory.config.BeanDefinitionVisitor.resolveValue(BeanDefinitionVisitor.java:198)
      at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitIndexedArgumentValues(BeanDefinitionVisitor.java:150)
      at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitBeanDefinition(BeanDefinitionVisitor.java:84)
      at org.springframework.beans.factory.config.BeanDefinitionVisitor.resolveValue(BeanDefinitionVisitor.java:169)
      at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitPropertyValues(BeanDefinitionVisitor.java:141)
      at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitBeanDefinition(BeanDefinitionVisitor.java:82)
      at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:208)
      ... 18 more
  </code></pre>
  <p>UPD 2.
  The problem is in property-placeholder placed in datasource-tx-jpa.xml, which is imported in root-context.xml before security-context.xml. So it can't find placeholder in property file associated with datasource-tx-jpa.xml.
  The attribute &quot;ignore-unresolvable&quot; of property-placeholder should be set to true in the first imported context.</p>