EnvironmentAwareは、運用環境変数を取得することと、使用:ロード・コンフィギュレーション・ファイル

インタフェースEnvironmentAware

  • org.springframework.context.EnvironmentAware

    • setEnvironment(環境環境)
  • このインタフェースBeanのいずれかの実装では、その実行中の環境を取得します

setEnvironment(環境環境)

  • 実行しているこの環境のコンポーネントを設定します。

利用シナリオ

  1. 負荷プロファイル
    シーンワン@configration的配置类读取properties中的值
@Configuration
 public class MyConfig implements EnvironmentAware {
    private static Environment env;
    
    @Override
    public void setEnvironment(Environment environment) {
        env=environment;
    }
    
    // ... 
    // todo : 读取env中的值 用来配置其他对象
 }

リリース8元の記事 ウォンの賞賛1 ビュー135

おすすめ

転載: blog.csdn.net/C_Wangjq/article/details/105377193