SpringCloud
雪崩效應:
雪崩效應的解決辦法:斷路器(circuit Breqkers)
分佈式的配置中心:
加入依賴
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.SR4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
</dependencies>
@EnableConfigServer:啓用分佈式配置中心 讀取遠程git倉庫獲取配置
所有spring的配置中心的配置文件都有以下幾種格式組成
* 1.配置文件屬於哪個應用的(application)
* 2.配置文件屬於哪個階段(profile) 開發階段 測試階段 產品階段
* 3.在git倉庫中哪個分支下(label)
在服務端獲取git上的數據源(application.properties)
spring.cloud.config.server.git.uri=https://github.com/RayaCL/confiServer
server.port=8089
分佈式配置中心的客戶端配置
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.SR4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
</dependencies>
在客戶端創建bootstrap.properties鏈接數據源
spring.cloud.config.uri=http://localhost:8089
spring.application.name=jdbc
spring.profiles.active=dev
獲取數據源
package cn.et;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.alibaba.druid.pool.DruidDataSource;
@Configuration
public class Config {
@Value("${password}")
private String password;
@Value("${driverClass}")
private String driverClass;
@Value("${url}")
private String url;
@Value("${username1}")
private String username1;
@Bean
public DataSource myDataSource(){
DruidDataSource dds=new DruidDataSource();
dds.setUrl(url);
dds.setDriverClassName(driverClass);
dds.setUsername(username1);
dds.setPassword(password);
return dds;
}
}