Spring配置属性管理(二)— Environment

在上一篇文章中我们从@Value注解入手大致讲解了一下配置属性在Spring项目中应用的基本原理,本文将会围绕Spring的Environment对org.springframework.core.env包中的重要类进行进一步的解析。

The Environment interface is an abstraction integrated in the container that models two key aspects of the application environment: profiles and properties.

A profile is a named, logical group of bean definitions to be registered with the container only if the given profile is active. Beans may be assigned to a profile whether defined in XML or with annotations. The role of the Environment object with relation to profiles is in determining which profiles (if any) are currently active, and which profiles (if any) should be active by default.

Properties play an important role in almost all applications and may originate from a variety of sources: properties files, JVM system properties, system environment variables, JNDI, servlet context parameters, ad-hoc Properties objects, Map objects, and so on. The role of the Environment object with relation to properties is to provide the user with a convenient service interface for configuring property sources and resolving properties from them.

在Spring的官方文档中我们可以得知,在Spring框架中Environment主要负责两个Profiles于Properties两个部分。这两个部分对于我们而言基本上是耳熟能详的了,Profiles通常用于应用区分环境(例如测试、预发、正式加载不同的属性配置或者是Bean配置),Properties则是Spring用于管理配置文件属性的重要组件。本文我们重点关注一下Properties相关的原理

你可能感兴趣的:(Spring配置属性管理(二)— Environment)