深入理解SpringCloud之分布式配置

  Spring Cloud Config Server能够统一管理配置,我们绝大多数情况都是基于git或者svn作为其配置仓库,其实SpringCloud还可以把数据库作为配置仓库,今天我们就来了解一下。顺便分析一下其实现原理。

一、PropertySourceLocator接口 1.1、代码分析

  这个接口的作用用于定制化引导配置,通过这个接口我们可以通过代码动态的向Environment中添加PropertySource,该接口定义如下:

深入理解SpringCloud之分布式配置

深入理解SpringCloud之分布式配置

/* * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.springframework.cloud.bootstrap.config; import org.springframework.core.env.Environment; import org.springframework.core.env.PropertySource; /** * Strategy for locating (possibly remote) property sources for the Environment. * Implementations should not fail unless they intend to prevent the application from * starting. * * @author Dave Syer * */ public interface PropertySourceLocator { /** * @param environment the current Environment * @return a PropertySource or null if there is none * * @throws IllegalStateException if there is a fail fast condition */ PropertySource<?> locate(Environment environment); }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zyyszf.html