EnvironmentAware; obtaining operational environment variables; use: load configuration file

Interface EnvironmentAware

  • org.springframework.context.EnvironmentAware

    • setEnvironment(Environment environment)
  • Any implementation of this interface bean will get its running environment

setEnvironment(Environment environment)

  • Set this environment components running.

scenes to be used

  1. Load Profile
    Scene One :@configration的配置类读取properties中的值
@Configuration
 public class MyConfig implements EnvironmentAware {
    private static Environment env;
    
    @Override
    public void setEnvironment(Environment environment) {
        env=environment;
    }
    
    // ... 
    // todo : 读取env中的值 用来配置其他对象
 }

Released eight original articles · won praise 1 · views 135

Guess you like

Origin blog.csdn.net/C_Wangjq/article/details/105377193