zoukankan      html  css  js  c++  java
  • 36 SpringBoot 在系统配置文件中动态加载配置

    1. 动态加载配置

    package com.thc.rcm.system.config;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.env.EnvironmentPostProcessor;
    import org.springframework.core.env.ConfigurableEnvironment;
    import org.springframework.core.env.MutablePropertySources;
    import org.springframework.core.env.PropertiesPropertySource;
    import org.springframework.stereotype.Component;
    
    import java.util.Properties;
    
    /**
     * @author shizhanwei
     * 1.代替yml文件中原服务地址的配置,其它服务名称变动需修改这里
     * 2.yml文件中的下面配置可以删除了
     * 例如:
     * feign:
     *   base: /
     *   rcm: rcm/
     *
     */
    @Component
    public class AppEnvPostProcessor implements EnvironmentPostProcessor {
    
        @Override
        public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
            MutablePropertySources propertySources = environment.getPropertySources();
            Properties properties = new Properties();
            properties.setProperty("feign.base","/");
            properties.setProperty("feign.rcm","rcm/");
            properties.setProperty("feign.warehouse","warehouse/");
            properties.setProperty("feign.sob","sob/");
            properties.setProperty("feign.phr","thc-phr/");
            properties.setProperty("feign.passport","c-union/");
            properties.setProperty("feign.market","market/");
            properties.setProperty("feign.mall","c-mall/");
            properties.setProperty("feign.cunion","c-union/");
            properties.setProperty("feign.insurance","insurance/");
            properties.setProperty("feign.permission","thc-platform-core/");
            properties.setProperty("feign.msg","msg/");
            properties.setProperty("feign.epay","epay/");
            properties.setProperty("feign.arrange","arrange/");
            properties.setProperty("feign.medicalrecord","medical-record/");
            properties.setProperty("feign.workbench","workbench/");
            properties.setProperty("feign.pricemanage","pricemanage/");
            properties.setProperty("feign.process-engine","process-engine/");
            propertySources.addLast(new PropertiesPropertySource("thc_apps",properties));
        }
    }

    2. 在代码中引用:

        @Autowired
        Environment env;
    
        @PostMapping(value = "/testEnv")
        public Object testEnv() {
            return env.getProperty("feign.pricemanage");
        }
  • 相关阅读:
    如何找出阻塞的线程正在等待哪个线程
    探索Windows 10的CFG机制
    异常0xc000041d的抛出过程
    异常STATUS_FATAL_USER_CALLBACK_EXCEPTION(0xc000041d)
    VisualStudio中集成扩展调试SOS
    clr调试扩展和DAC
    WinDbg常用命令系列---sx, sxd, sxe, sxi, sxn, sxr, sx- (设置异常)
    CLR调试时的sos.dll/clr.dll/mscorwks.dll/mscordacwks.dll等动态库的版本对应
    WinDbg常用命令系列---!runaway
    WinDbg常用命令系列---!findstack
  • 原文地址:https://www.cnblogs.com/guchunchao/p/11785182.html
Copyright © 2011-2022 走看看