36 SpringBoot arranged in dynamic loading system configuration file

1. Dynamic load configuration

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 the java.util.Properties; 

/ ** 
 * @author shizhanwei 
 * yml configuration file instead of 1. Central service address, other changes need to modify the service name here 
 * 2.yml the following configuration file can be deleted 
 * For example: 
 * 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. references in the code:

    @Autowired
    Environment env;

    @PostMapping(value = "/testEnv")
    public Object testEnv() {
        return env.getProperty("feign.pricemanage");
    }

 

 

 

 

Guess you like

Origin www.cnblogs.com/guchunchao/p/11785182.html
Recommended