Skip to content

Commit f60a40b

Browse files
committed
Polish Environment subsystem Javadoc
1 parent 3920c5a commit f60a40b

File tree

6 files changed

+65
-44
lines changed

6 files changed

+65
-44
lines changed

org.springframework.core/src/main/java/org/springframework/core/env/AbstractEnvironment.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,16 @@
3838
* through the {@link #ACTIVE_PROFILES_PROPERTY_NAME} and
3939
* {@link #DEFAULT_PROFILES_PROPERTY_NAME} properties.
4040
*
41+
* <p>Concrete subclasses differ primarily on which {@link PropertySource} objects they
42+
* add by default. {@code AbstractEnvironment} adds none. Subclasses should contribute
43+
* property sources through the protected {@link #customizePropertySources()} hook, while
44+
* clients should customize using {@link ConfigurableEnvironment#getPropertySources()} and
45+
* working against the {@link MutablePropertySources} API. See
46+
* {@link ConfigurableEnvironment} Javadoc for usage examples.
47+
*
4148
* @author Chris Beams
4249
* @since 3.1
50+
* @see ConfigurableEnvironment
4351
* @see StandardEnvironment
4452
*/
4553
public abstract class AbstractEnvironment implements ConfigurableEnvironment {

org.springframework.core/src/main/java/org/springframework/core/env/ConfigurableEnvironment.java

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,49 @@
2020

2121
/**
2222
* Configuration interface to be implemented by most if not all {@link Environment} types.
23-
* Provides facilities for setting active and default profiles as well
24-
* as accessing underlying {@linkplain #getPropertySources() property sources}.
23+
* Provides facilities for setting active and default profiles and manipulating underlying
24+
* property sources. Allows clients to set and validate required properties, customize the
25+
* conversion service and more through the {@link ConfigurablePropertyResolver}
26+
* superinterface.
27+
*
28+
* <h2>Manipulating property sources</h2>
29+
* <p>Property sources may be removed, reordered, or replaced; and additional
30+
* property sources may be added using the {@link MutablePropertySources}
31+
* instance returned from {@link #getPropertySources()}. The following examples
32+
* are against the {@link StandardEnvironment} implementation of
33+
* {@code ConfigurableEnvironment}, but are generally applicable to any implementation,
34+
* though particular default property sources may differ.
35+
*
36+
* <h4>Example: adding a new property source with highest search priority</h4>
37+
* <pre class="code">
38+
* ConfigurableEnvironment environment = new StandardEnvironment();
39+
* MutablePropertySources propertySources = environment.getPropertySources();
40+
* Map<String, String> myMap = new HashMap<String, String>();
41+
* myMap.put("xyz", "myValue");
42+
* propertySources.addFirst(new MapPropertySource("MY_MAP", myMap));
43+
* </pre>
44+
*
45+
* <h4>Example: removing the default system properties property source</h4>
46+
* <pre class="code">
47+
* MutablePropertySources propertySources = environment.getPropertySources();
48+
* propertySources.remove(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)
49+
* </pre>
50+
*
51+
* <h4>Example: mocking the system environment for testing purposes</h4>
52+
* <pre class="code">
53+
* MutablePropertySources propertySources = environment.getPropertySources();
54+
* MockPropertySource mockEnvVars = new MockPropertySource().withProperty("xyz", "myValue");
55+
* propertySources.replace(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, mockEnvVars);
56+
* </pre>
57+
*
58+
* When an {@link Environment} is being used by an ApplicationContext, it is important
59+
* that any such PropertySource manipulations be performed <em>before</em> the context's
60+
* {@link org.springframework.context.support.AbstractApplicationContext#refresh()
61+
* refresh()} method is called. This ensures that all property sources are available
62+
* during the container bootstrap process, including use by
63+
* {@linkplain org.springframework.context.support.PropertySourcesPlaceholderConfigurer
64+
* property placeholder configurers}.
65+
*
2566
*
2667
* @author Chris Beams
2768
* @since 3.1

org.springframework.core/src/main/java/org/springframework/core/env/ConfigurablePropertyResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
/**
2222
* Configuration interface to be implemented by most if not all {@link PropertyResolver
23-
* PropertyResolvers}. Provides facilities for accessing and customizing the
23+
* PropertyResolver} types. Provides facilities for accessing and customizing the
2424
* {@link org.springframework.core.convert.ConversionService ConversionService} used when
2525
* converting property values from one type to another.
2626
*

org.springframework.core/src/main/java/org/springframework/core/env/Environment.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
/**
2020
* Interface representing the environment in which the current application is running.
2121
* Models two key aspects of the application environment: <em>profiles</em> and
22-
* <em>properties</em>.
22+
* <em>properties</em>. Methods related to property access are exposed via the
23+
* {@link PropertyResolver} superinterface.
2324
*
2425
* <p>A <em>profile</em> is a named, logical group of bean definitions to be registered
2526
* with the container only if the given profile is <em>active</em>. Beans may be assigned
@@ -37,7 +38,7 @@
3738
* provide the user with a convenient service interface for configuring property sources
3839
* and resolving properties from them.
3940
*
40-
* <p>Beans managed within an ApplicationContext may register to be {@link
41+
* <p>Beans managed within an {@code ApplicationContext} may register to be {@link
4142
* org.springframework.context.EnvironmentAware EnvironmentAware} or {@code @Inject} the
4243
* {@code Environment} in order to query profile state or resolve properties directly.
4344
*
@@ -50,10 +51,10 @@
5051
* {@code <context:property-placeholder/>}.
5152
*
5253
* <p>Configuration of the environment object must be done through the
53-
* {@link ConfigurableEnvironment} interface, returned from all
54+
* {@code ConfigurableEnvironment} interface, returned from all
5455
* {@code AbstractApplicationContext} subclass {@code getEnvironment()} methods. See
55-
* {@link StandardEnvironment} for several examples of using the ConfigurableEnvironment
56-
* interface to manipulate property sources prior to application context refresh().
56+
* {@link ConfigurableEnvironment} Javadoc for usage examples demonstrating manipulation
57+
* of property sources prior to application context {@code refresh()}.
5758
*
5859
* @author Chris Beams
5960
* @since 3.1

org.springframework.core/src/main/java/org/springframework/core/env/StandardEnvironment.java

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,45 +30,16 @@
3030
*
3131
* That is, if the key "xyz" is present both in the JVM system properties as well as in
3232
* the set of environment variables for the current process, the value of key "xyz" from
33-
* system properties * will return from a call to {@code environment.getProperty("xyz")}.
33+
* system properties will return from a call to {@code environment.getProperty("xyz")}.
3434
* This ordering is chosen by default because system properties are per-JVM, while
3535
* environment variables may be the same across many JVMs on a given system. Giving
3636
* system properties precedence allows for overriding of environment variables on a
3737
* per-JVM basis.
3838
*
3939
* <p>These default property sources may be removed, reordered, or replaced; and
4040
* additional property sources may be added using the {@link MutablePropertySources}
41-
* instance available from {@link #getPropertySources()}.
42-
*
43-
* <h4>Example: adding a new property source with highest search priority</h4>
44-
* <pre class="code">
45-
* ConfigurableEnvironment environment = new StandardEnvironment();
46-
* MutablePropertySources propertySources = environment.getPropertySources();
47-
* Map<String, String> myMap = new HashMap<String, String>();
48-
* myMap.put("xyz", "myValue");
49-
* propertySources.addFirst(new MapPropertySource("MY_MAP", myMap));
50-
* </pre>
51-
*
52-
* <h4>Example: removing the default system properties property source</h4>
53-
* <pre class="code">
54-
* MutablePropertySources propertySources = environment.getPropertySources();
55-
* propertySources.remove(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)
56-
* </pre>
57-
*
58-
* <h4>Example: mocking the system environment for testing purposes</h4>
59-
* <pre class="code">
60-
* MutablePropertySources propertySources = environment.getPropertySources();
61-
* MockPropertySource mockEnvVars = new MockPropertySource().withProperty("xyz", "myValue");
62-
* propertySources.replace(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, mockEnvVars);
63-
* </pre>
64-
*
65-
* When an {@link Environment} is being used by an ApplicationContext, it is important
66-
* that any such PropertySource manipulations be performed <em>before</em> the context's
67-
* {@link org.springframework.context.support.AbstractApplicationContext#refresh()
68-
* refresh()} method is called. This ensures that all PropertySources are available during
69-
* the container bootstrap process, including use by
70-
* {@linkplain org.springframework.context.support.PropertySourcesPlaceholderConfigurer
71-
* property placeholder configurers}.
41+
* instance available from {@link #getPropertySources()}. See
42+
* {@link ConfigurableEnvironment} Javadoc for usage examples.
7243
*
7344
* @author Chris Beams
7445
* @since 3.1

org.springframework.web/src/main/java/org/springframework/web/context/support/StandardServletEnvironment.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ public class StandardServletEnvironment extends StandardEnvironment {
6565
* {@value #JNDI_PROPERTY_SOURCE_NAME}.
6666
* <p>Properties in any of the above will take precedence over system properties and
6767
* environment variables contributed by the {@link StandardEnvironment} superclass.
68-
* <p>The {@code Servlet}-related property sources are added as stubs for now, and
69-
* will be {@linkplain WebApplicationContextUtils#initServletPropertySources fully
70-
* initialized} once the actual {@link ServletConfig} and {@link ServletContext}
71-
* objects are available.
68+
* <p>The {@code Servlet}-related property sources are added as {@link
69+
* StubPropertySource stubs} at this stage, and will be {@linkplain
70+
* WebApplicationContextUtils#initServletPropertySources fully initialized} once the
71+
* actual {@link ServletConfig} and {@link ServletContext} objects become available.
7272
* @see StandardEnvironment#customizePropertySources
7373
* @see org.springframework.core.env.AbstractEnvironment#customizePropertySources
7474
* @see ServletConfigPropertySource

0 commit comments

Comments
 (0)