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"); }
原文地址:https://www.cnblogs.com/guchunchao/p/11785182.html
时间: 2024-10-10 07:58:21