博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Zipkin-1.19.0学习系列5:listeners.environmentPrepared(environment)&配置文件解析
阅读量:5895 次
发布时间:2019-06-19

本文共 7775 字,大约阅读时间需要 25 分钟。

hot3.png

当创建了一个StandServletEnvironment对象时,会触发事件,分析下做了哪些事情。

---

@Override	public void environmentPrepared(ConfigurableEnvironment environment) {		this.initialMulticaster.multicastEvent(new ApplicationEnvironmentPreparedEvent(				this.application, this.args, environment));	}

可以看到又做了一次分发事件。

---

 1)ConfigFileApplicationListener

private void onApplicationEnvironmentPreparedEvent(			ApplicationEnvironmentPreparedEvent event) {		//接收事件		List
postProcessors = loadPostProcessors(); //加上自己 postProcessors.add(this); // AnnotationAwareOrderComparator.sort(postProcessors); // for (EnvironmentPostProcessor postProcessor : postProcessors) { postProcessor.postProcessEnvironment(event.getEnvironment(), event.getSpringApplication()); } }

具体的postProcessors有

main[1] print postProcessors postProcessors = "[org.springframework.boot.env.SpringApplicationJsonEnvironmentPostProcessor@2767e23c, org.springframework.boot.cloud.CloudFoundryVcapEnvironmentPostProcessor@710c2b53, org.springframework.boot.context.config.ConfigFileApplicationListener@498d318c]"

下面一个一个分析

1.1)SpringApplicationJsonEnvironmentPostProcessor.postProcessEnvironment

什么都不做

1.2)CloudFoundryVcapEnvironmentPostProcessor.postProcessEnvironment

Step completed: "thread=main", org.springframework.boot.cloud.CloudFoundryVcapEnvironmentPostProcessor.postProcessEnvironment(), line=119 bci=0119    		if (CloudPlatform.CLOUD_FOUNDRY.isActive(environment)) {main[1] next> Step completed: "thread=main", org.springframework.boot.cloud.CloudFoundryVcapEnvironmentPostProcessor.postProcessEnvironment(), line=137 bci=95137    	}

仍然什么都不做!

1.3)ConfigFileApplicationListener自己的处理

这个里面会加载配置文件

protected void addPropertySources(ConfigurableEnvironment environment,			ResourceLoader resourceLoader) {		//这里		RandomValuePropertySource.addToEnvironment(environment);		//这里加载配置文件		try {			new Loader(environment, resourceLoader).load();		}		catch (IOException ex) {			throw new IllegalStateException("Unable to load configuration files", ex);		}	}

加载的配置文件路径有

main[1] print locations locations = "[file:./config/, file:./, classpath:/config/, classpath:/]"

---第一组

1)首先尝试加载location = "file:./config/zipkin-server.properties"

2)然后尝试加载 resource = "URL [file:./config/zipkin-server.xml]"

3)接着尝试加载 location = "file:./config/zipkin-server.yml"

4)最后尝试加载  location = "file:./config/zipkin-server.yaml"

---第二组

1)首先尝试加载 location = "file:./zipkin-server.properties"

2)然后尝试加载location = "file:./zipkin-server.xml"

3)接着尝试加载location = "file:./zipkin-server.yml"

4)最后尝试加载~location = "file:./zipkin-server.yaml"

其中第3步的代码为

@Override	public PropertySource
load(String name, Resource resource, String profile) throws IOException { if (ClassUtils.isPresent("org.yaml.snakeyaml.Yaml", null)) { Processor processor = new Processor(resource, profile); Map
source = processor.process(); if (!source.isEmpty()) { return new MapPropertySource(name, source); } } return null; }

---第3组

1)location = "classpath:/config/zipkin-server.properties"

2)location = "classpath:/config/zipkin-server.xml"

3)location = "classpath:/config/zipkin-server.yml"

4)location = "classpath:/config/zipkin-server.yaml"

---第4组

1)location = "classpath:/zipkin-server.properties"

2)"classpath:/zipkin-server.xml"

3)location = "classpath:/zipkin-server.yml"

4)location = "classpath:/zipkin-server.yaml"

===因为配置文件里配置的是shared,所以开始了新的一轮配置文件读取

---第1组

1)location = "file:./config/zipkin-server-shared.properties"

剩下的就不用多说了,反正最终加载了zipkin-server-shared.yml

那么得到的结果就是:

Step completed: "thread=main", org.springframework.boot.env.YamlPropertySourceLoader.load(), line=59 bci=2759    			if (!source.isEmpty()) {main[1] print source source = "{zipkin.self-tracing.enabled=${SELF_TRACING_ENABLED:false}, zipkin.self-tracing.sample-rate=${SELF_TRACING_SAMPLE_RATE:1.0}, zipkin.self-tracing.flush-interval=${SELF_TRACING_FLUSH_INTERVAL:1}, zipkin.collector.sample-rate=${COLLECTOR_SAMPLE_RATE:1.0}, zipkin.collector.kafka.zookeeper=${KAFKA_ZOOKEEPER:}, zipkin.collector.kafka.topic=${KAFKA_TOPIC:zipkin}, zipkin.collector.kafka.group-id=${KAFKA_GROUP_ID:zipkin}, zipkin.collector.kafka.streams=${KAFKA_STREAMS:1}, zipkin.collector.kafka.max-message-size=${KAFKA_MAX_MESSAGE_SIZE:1048576}, zipkin.collector.scribe.enabled=${SCRIBE_ENABLED:true}, zipkin.collector.scribe.category=zipkin, zipkin.collector.scribe.port=${COLLECTOR_PORT:9410}, zipkin.query.lookback=${QUERY_LOOKBACK:86400000}, zipkin.query.names-max-age=300, zipkin.query.allowed-origins=*, zipkin.storage.strict-trace-id=${STRICT_TRACE_ID:true}, zipkin.storage.type=${STORAGE_TYPE:mem}, zipkin.storage.cassandra.contact-points=${CASSANDRA_CONTACT_POINTS:localhost}, zipkin.storage.cassandra.local-dc=${CASSANDRA_LOCAL_DC:}, zipkin.storage.cassandra.username=${CASSANDRA_USERNAME:}, zipkin.storage.cassandra.password=${CASSANDRA_PASSWORD:}, zipkin.storage.cassandra.keyspace=${CASSANDRA_KEYSPACE:zipkin}, zipkin.storage.cassandra.max-connections=${CASSANDRA_MAX_CONNECTIONS:8}, zipkin.storage.cassandra.ensure-schema=${CASSANDRA_ENSURE_SCHEMA:true}, zipkin.storage.cassandra.span-ttl=${CASSANDRA_SPAN_TTL:604800}, zipkin.storage.cassandra.index-ttl=${CASSANDRA_INDEX_TTL:259200}, zipkin.storage.cassandra.index-cache-max=${CASSANDRA_INDEX_CACHE_MAX:100000}, zipkin.storage.cassandra.index-cache-ttl=${CASSANDRA_INDEX_CACHE_TTL:60}, zipkin.storage.cassandra.index-fetch-multiplier=${CASSANDRA_INDEX_FETCH_MULTIPLIER:3}, zipkin.storage.cassandra.use-ssl=${CASSANDRA_USE_SSL:false}, zipkin.storage.cassandra3.contact-points=${CASSANDRA3_CONTACT_POINTS:localhost}, zipkin.storage.cassandra3.local-dc=${CASSANDRA3_LOCAL_DC:}, zipkin.storage.cassandra3.username=${CASSANDRA3_USERNAME:}, zipkin.storage.cassandra3.password=${CASSANDRA3_PASSWORD:}, zipkin.storage.cassandra3.keyspace=${CASSANDRA3_KEYSPACE:zipkin3}, zipkin.storage.cassandra3.max-connections=${CASSANDRA3_MAX_CONNECTIONS:8}, zipkin.storage.cassandra3.ensure-schema=${CASSANDRA3_ENSURE_SCHEMA:true}, zipkin.storage.cassandra3.index-fetch-multiplier=${CASSANDRA3_INDEX_FETCH_MULTIPLIER:3}, zipkin.storage.cassandra3.use-ssl=${CASSANDRA3_USE_SSL:false}, zipkin.storage.elasticsearch.cluster=${ES_CLUSTER:elasticsearch}, zipkin.storage.elasticsearch.hosts=${ES_HOSTS:}, zipkin.storage.elasticsearch.pipeline=${ES_PIPELINE:}, zipkin.storage.elasticsearch.max-requests=${ES_MAX_REQUESTS:64}, zipkin.storage.elasticsearch.aws.domain=${ES_AWS_DOMAIN:}, zipkin.storage.elasticsearch.aws.region=${ES_AWS_REGION:}, zipkin.storage.elasticsearch.index=${ES_INDEX:zipkin}, zipkin.storage.elasticsearch.index-shards=${ES_INDEX_SHARDS:5}, zipkin.storage.elasticsearch.index-replicas=${ES_INDEX_REPLICAS:1}, zipkin.storage.mysql.host=${MYSQL_HOST:localhost}, zipkin.storage.mysql.port=${MYSQL_TCP_PORT:3306}, zipkin.storage.mysql.username=${MYSQL_USER:}, zipkin.storage.mysql.password=${MYSQL_PASS:}, zipkin.storage.mysql.db=${MYSQL_DB:zipkin}, zipkin.storage.mysql.max-active=${MYSQL_MAX_CONNECTIONS:10}, zipkin.storage.mysql.use-ssl=${MYSQL_USE_SSL:false}, zipkin.ui.query-limit=10, zipkin.ui.environment=, zipkin.ui.default-lookback=3600000, zipkin.ui.instrumented=.*, server.port=${QUERY_PORT:9411}, server.compression.enabled=true, server.compression.mime-types=application/json,application/javascript,text/css,image/svg, spring.mvc.favicon.enabled=false, spring.autoconfigure.exclude[0]=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration, spring.autoconfigure.exclude[1]=org.springframework.boot.autoconfigure.elasticsearch.jest.JestAutoConfiguration, info.zipkin.version=1.19.0, logging.level.com.facebook.swift.service.ThriftServiceProcessor=OFF}"

---

然后接下来的一个listener就是

org.springframework.boot.autoconfigure.BackgroundPreinitializer.onApplicationEvent

主要做一些后台初始化工作,

---

 

转载于:https://my.oschina.net/qiangzigege/blog/821058

你可能感兴趣的文章
开发进度——4
查看>>
Netty 4.1.35.Final 发布,经典开源 Java 网络服务框架
查看>>
Eclipse中修改代码格式
查看>>
关于 error: LINK1123: failure during conversion to COFF: file invalid or corrupt 错误的解决方案...
查看>>
Linux 进程中 Stop, Park, Freeze【转】
查看>>
PHP盛宴——经常使用函数集锦
查看>>
安装gulp及相关插件
查看>>
如何在Linux用chmod来修改所有子目录中的文件属性?
查看>>
Hyper-V 2016 系列教程30 机房温度远程监控方案
查看>>
笔记:认识.NET平台
查看>>
cocos2d中CCAnimation的使用(cocos2d 1.0以上版本)
查看>>
gitlab 完整部署实例
查看>>
影响企业信息化成败的几点因素
查看>>
SCCM 2016 配置管理系列(Part8)
查看>>
struts中的xwork源码下载地址
查看>>
我的友情链接
查看>>
PHP 程序员的技术成长规划
查看>>
python基础教程_学习笔记19:标准库:一些最爱——集合、堆和双端队列
查看>>
js replace,正则截取字符串内容
查看>>
javascript继承方式详解
查看>>