ApplicationContext ctx = new GenericApplicationContext();
Environment env = ctx.getEnvironment();
boolean containsMyProperty = env.containsProperty("my-property");
System.out.println("Does my environment contain the 'my-property' property? " + containsMyProperty);
val ctx = GenericApplicationContext()
val env = ctx.environment
val containsMyProperty = env.containsProperty("my-property")
println("Does my environment contain the 'my-property' property? $containsMyProperty")
In the preceding snippet, we see a high-level way of asking Spring whether the my-property property is
defined for the current environment. To answer this question, the Environment object performs
a search over a set of PropertySource
objects. A PropertySource is a simple abstraction over any source of key-value pairs, and
Spring’s StandardEnvironment
is configured with two PropertySource objects — one representing the set of JVM system properties
(System.getProperties()) and one representing the set of system environment variables
(System.getenv()).
PropertySource 是Spring对配置数据源的抽象
In the preceding snippet, we see a high-level way of asking Spring whether the
my-property
property is defined for the current environment. To answer this question, theEnvironment
object performs a search over a set ofPropertySource
objects. APropertySource
is a simple abstraction over any source of key-value pairs, and Spring’sStandardEnvironment
is configured with two PropertySource objects — one representing the set of JVM system properties (System.getProperties()
) and one representing the set of system environment variables (System.getenv()
).