翻源码可以发现
读取接口
org.eclipse.microprofile.config.spi.ConfigSourceProvider
实现类
// 从环境变量中读取
io.smallrye.config.DotEnvConfigSourceProvider
// classpath中读取application.properties
io.quarkus.runtime.configuration.ApplicationPropertiesConfigSourceLoader.InClassPath
// 文件系统中读取 System.getProperty("user.dir"), "config", "application.properties"
io.quarkus.runtime.configuration.ApplicationPropertiesConfigSourceLoader.InFileSystem
io.smallrye.config.SmallRyeConfig.ConfigSources#buildSources
private static List<ConfigSource> buildSources(final SmallRyeConfigBuilder builder) {
List<ConfigSource> sourcesToBuild = new ArrayList<>(builder.getSources());
// 提供配置的来源: 环境变量、classpath、fileSystem
for (ConfigSourceProvider sourceProvider : builder.getSourceProviders()) {
// 从来源中获取配置源,如从classpath中获取所有application.properties作为ConfigSource实例供后续获取配置
for (ConfigSource configSource : sourceProvider.getConfigSources(builder.getClassLoader())) {
sourcesToBuild.add(configSource);
}
}
if (builder.isAddDiscoveredSources()) {
sourcesToBuild.addAll(builder.discoverSources());
}
if (builder.isAddDefaultSources()) {
sourcesToBuild.addAll(builder.getDefaultSources());
}
sourcesToBuild.add(new DefaultValuesConfigSource(builder.getDefaultValues()));
return sourcesToBuild;
}
顺带说一下这个源码的切入点,为增加一个config拦截器,通过debug找栈找到的。
标签:sourcesToBuild,读取,builder,几种,Quarkus,io,config,quarkus From: https://www.cnblogs.com/xiaojiluben/p/17901317.html