|
|
|
|
@@ -136,7 +136,6 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
|
|
|
|
|
customizePropertySources(propertySources);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Factory method used to create the {@link ConfigurablePropertyResolver}
|
|
|
|
|
* instance used by the Environment.
|
|
|
|
|
@@ -166,6 +165,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
|
|
|
|
|
* sources using {@link MutablePropertySources#addLast(PropertySource)} such that
|
|
|
|
|
* further subclasses may call {@code super.customizePropertySources()} with
|
|
|
|
|
* predictable results. For example:
|
|
|
|
|
*
|
|
|
|
|
* <pre class="code">
|
|
|
|
|
* public class Level1Environment extends AbstractEnvironment {
|
|
|
|
|
* @Override
|
|
|
|
|
@@ -185,11 +185,13 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
|
|
|
|
|
* }
|
|
|
|
|
* }
|
|
|
|
|
* </pre>
|
|
|
|
|
* In this arrangement, properties will be resolved against sources A, B, C, D in that
|
|
|
|
|
*
|
|
|
|
|
* <p>In this arrangement, properties will be resolved against sources A, B, C, D in that
|
|
|
|
|
* order. That is to say that property source "A" has precedence over property source
|
|
|
|
|
* "D". If the {@code Level2Environment} subclass wished to give property sources C
|
|
|
|
|
* and D higher precedence than A and B, it could simply call
|
|
|
|
|
* {@code super.customizePropertySources} after, rather than before adding its own:
|
|
|
|
|
*
|
|
|
|
|
* <pre class="code">
|
|
|
|
|
* public class Level2Environment extends Level1Environment {
|
|
|
|
|
* @Override
|
|
|
|
|
@@ -200,25 +202,24 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
|
|
|
|
|
* }
|
|
|
|
|
* }
|
|
|
|
|
* </pre>
|
|
|
|
|
* The search order is now C, D, A, B as desired.
|
|
|
|
|
*
|
|
|
|
|
* <p>Beyond these recommendations, subclasses may use any of the {@code add*},
|
|
|
|
|
* <p>The search order is now C, D, A, B as desired.
|
|
|
|
|
* <p>Beyond these recommendations, subclasses may use any of the {@code add*},
|
|
|
|
|
* {@code remove}, or {@code replace} methods exposed by {@link MutablePropertySources}
|
|
|
|
|
* in order to create the exact arrangement of property sources desired.
|
|
|
|
|
*
|
|
|
|
|
* <p>The base implementation registers no property sources.
|
|
|
|
|
*
|
|
|
|
|
* <p>Note that clients of any {@link ConfigurableEnvironment} may further customize
|
|
|
|
|
* property sources via the {@link #getPropertySources()} accessor, typically within
|
|
|
|
|
* an {@link org.springframework.context.ApplicationContextInitializer
|
|
|
|
|
* ApplicationContextInitializer}. For example:
|
|
|
|
|
*
|
|
|
|
|
* <pre class="code">
|
|
|
|
|
* ConfigurableEnvironment env = new StandardEnvironment();
|
|
|
|
|
* env.getPropertySources().addLast(new PropertySourceX(...));
|
|
|
|
|
* </pre>
|
|
|
|
|
*
|
|
|
|
|
* <h2>A warning about instance variable access</h2>
|
|
|
|
|
* Instance variables declared in subclasses and having default initial values should
|
|
|
|
|
* <p>Instance variables declared in subclasses and having default initial values should
|
|
|
|
|
* <em>not</em> be accessed from within this method. Due to Java object creation
|
|
|
|
|
* lifecycle constraints, any initial value will not yet be assigned when this
|
|
|
|
|
* callback is invoked by the {@link #AbstractEnvironment()} constructor, which may
|
|
|
|
|
@@ -227,7 +228,6 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
|
|
|
|
|
* property source manipulation and instance variable access directly within the
|
|
|
|
|
* subclass constructor. Note that <em>assigning</em> values to instance variables is
|
|
|
|
|
* not problematic; it is only attempting to read default values that must be avoided.
|
|
|
|
|
*
|
|
|
|
|
* @see MutablePropertySources
|
|
|
|
|
* @see PropertySourcesPropertyResolver
|
|
|
|
|
* @see org.springframework.context.ApplicationContextInitializer
|
|
|
|
|
|