Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>My existing solution involves defining a new MapAwareApplicationContext that takes a Map as an additional constructor argument.</p> <pre><code>public MapAwareApplicationContext(final URL[] configURLs, final String[] newConfigLocations, final Map&lt;String, String&gt; additionalProperties) { super(null); //standard constructor content here this.map = new HashMap&lt;String, String&gt;(additionalProperties); refresh(); } </code></pre> <p>It overrides postProcessBeanFactory() to add in a MapAwareProcessor:</p> <pre><code>protected void postProcessBeanFactory( final ConfigurableListableBeanFactory beanFactory) { beanFactory.addBeanPostProcessor(new MapAwareProcessor(this.map)); beanFactory.ignoreDependencyInterface(MapAware.class); } </code></pre> <p>The MapAwareProcessor implements postProcessBeforeInitialization() to inject the map into any type that implements the MapAware interface:</p> <pre><code>public Object postProcessBeforeInitialization(final Object bean, final String beanName) { if (this.map != null &amp;&amp; bean instanceof MapAware) { ((MapAware) bean).setMap(this.map); } return bean; } </code></pre> <p>I then add a new bean to my config to declare a MapAwarePropertyPlaceholderConfigurer:</p> <pre><code>&lt;bean id="propertyConfigurer" class="com.hsbc.r2ds.spring.MapAwarePropertyPlaceholderConfigurer"/&gt; </code></pre> <p>The configurer implements MapAware, so it will be injected with the Map as above. It then implements resolvePlaceholder() to resolve properties from the map, or delegate to the parent configurer:</p> <pre><code>protected String resolvePlaceholder(final String placeholder, final Properties props, final int systemPropertiesMode) { String propVal = null; if (this.map != null) { propVal = this.map.get(placeholder); } if (propVal == null) { propVal = super.resolvePlaceholder(placeholder, props); } return propVal; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload