title: How to achieve conditional resource import in a Spring XML context?
body: <p>What I would like to achieve is the ability to &quot;dynamically&quot; (i.e. based on a property defined in a configuration file) enable/disable the importing of a child Spring XML context.</p>
  <p>I imagine something like:</p>
  <pre><code>&lt;import condition=&quot;some.property.name&quot; resource=&quot;some-context.xml&quot;/&gt;
  </code></pre>
  <p>Where the property is resolved (to a boolean) and when true the context is imported, otherwise it isn't.</p>
  <p>Some of my research so far:</p>
  <ul>
  <li><p>Writing a custom NamespaceHandler (and related classes) so I can register my own custom element in my own namespace. For example: <code>&lt;myns:import condition=&quot;some.property.name&quot; resource=&quot;some-context.xml&quot;/&gt;</code></p>
  <p>The problem with this approach is that I do not want to replicate the entire resource importing logic from Spring and it isn't obvious to me what I need to delegate to to do this.</p>
  </li>
  <li><p>Overriding <code>DefaultBeanDefinitionDocumentReader</code> to extend the behaviour of the &quot;import&quot; element parsing and interpretation (which happens there in the <code>importBeanDefinitionResource</code> method). However I'm not sure where I can register this extension.</p>
  </li>
  </ul>