起首,我是前端 转 PHP 转 JAVA 得以为小白,文中讲得不对的地方请提出来,也欢迎来喷
起因是我司使用Eureka注册中心和 Configserver配置中心来达到多服务共享配置的问题,我好奇是如何从配置中心获取配置后,将配置写入消费方的。<hr>Eureka
这便引发了我4个小时追代码的过程
以上都是拷贝的,说白了,Eureka做的就是接口转发的概念<hr>SpringCloudConfig
12345678 | spring.application.name=quickstart-sampleeureka.client.serviceUrl.defaultZone=${QUICKSTART_EUREKAS:http://${QUICKSTART_USERNAME:admin}:${QUICKSTART_PASSWORD:123123}@localhost:20000/eureka/}spring.cloud.config.profile=framework,testspring.cloud.config.label=development-waynespring.cloud.config.discovery.enabled=truespring.cloud.config.discovery.serviceId=configserverspring.cloud.config.username=${QUICKSTART_USERNAME:admin} spring.cloud.config.password=${QUICKSTART_PASSWORD:123123} |
12 | response = restTemplate.exchange(uri + path, HttpMethod.GET, entity, Environment.class, args); |
12345678910111213141516171819 | @RequestMapping("/{name}/{profiles}/{label:.*}") public Environment labelled(@PathVariable String name, @PathVariable String profiles, @PathVariable String label) { if (name != null && name.contains("(_)")) { // "(_)" is uncommon in a git repo name, but "/" cannot be matched // by Spring MVC name = name.replace("(_)", "/"); } if (label != null && label.contains("(_)")) { // "(_)" is uncommon in a git branch name, but "/" cannot be matched // by Spring MVC label = label.replace("(_)", "/"); } Environment environment = this.repository.findOne(name, profiles, label); if(!acceptEmpty && (environment == null || environment.getPropertySources().isEmpty())){ throw new EnvironmentNotFoundException("Profile Not found"); } return environment; } |
12 | Map next = (Map) jdbc.query(this.sql, new Object[] { app, env, label }, this.extractor); |
123456 | for (PropertySource source : result.getPropertySources()) { @SuppressWarnings("unchecked") Map map = (Map) source .getSource(); composite.addPropertySource(new MapPropertySource(source.getName(), map));} |
其实我想追一下CompositePropertySource的源码,但是我饿~~了,
第一次写看源码的笔记,可能有些地方我自己懂了就跳过了,如果那里没写出来,欢迎提出来
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本文链接:https://blog.csdn.net/fengtianhe/article/details/109621900
欢迎光临 创意电子 (https://wxcydz.cc/) | Powered by Discuz! X3.4 |