SpringCloud Netflix相關(guān)代碼

一阿逃、bean模塊:二卧波、eureka7001模塊1.springBoot啟動類2时肿、yaml配置文件3、pom三港粱、eureka7002模塊yaml配置文件四螃成、服務(wù)提供者(mySc-dept)1、pom依賴2查坪、yaml配置3寸宏、config包下DeptConfig配置4、controller層DeptController5偿曙、mapper接口DeptMapper6氮凝、springBoot啟動類五、服務(wù)提供者2和服務(wù)提供者3(mySc-dept-provider-8002)yaml配置六望忆、服務(wù)消費者()1罩阵、pom依賴2、yaml配置3启摄、config配置(DeptConfig)4稿壁、controller層5、springBoot啟動類七歉备、feign(負載均衡)1常摧、pom2、yaml配置3威创、config層4落午、controller層5、springBoot啟動類八肚豺、Hystrix(服務(wù)熔斷)1溃斋、pom2、config層3吸申、controller層4梗劫、mapper5、springBoot啟動類6截碴、配置文件yaml九梳侨、zuul(服務(wù)路由網(wǎng)關(guān))1、pom2日丹、yaml配置3走哺、springBoot啟動類

一、bean模塊:

DeptService(接口)

<pre mdtype="fences" cid="n8" lang="java" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> package com.gk.service;

import com.gk.bean.Dept;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@FeignClient(value = "MYSC-DEPT")
@Component
public interface DeptService {

@RequestMapping("byId/{id}")
public Dept salById(@PathVariable(value = "id") Long id);
@RequestMapping("salList")
public List<Dept> salByList();

@RequestMapping("salByInfo")
public Object getDiscovery();
}</pre>

二哲虾、eureka7001模塊

1.springBoot啟動類

<pre mdtype="fences" cid="n16" lang="java" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> @SpringBootApplication
@EnableEurekaServer
public class EurekaStart {
public static void main( String[] args ){
SpringApplication.run(EurekaStart.class,args);
}
}</pre>

2丙躏、yaml配置文件

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="yaml" cid="n21" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> server:
port: 7001

eureka相關(guān)

eureka:
instance:
hostname: activate.navicat.com
client:
register-with-eureka: false #是否向eureka注冊中心注冊自己
fetch-registry: false #fetch-registry為false择示,表示注冊中心是自己
service-url:
defaultZone: http://activate.navicat2.com:7002/eureka/,http://activate.navicat3.com:7003/eureka/</pre>

3、pom

<pre mdtype="fences" cid="n26" lang="xml" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> <dependencies>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
<version>1.3.4.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies></pre>

三晒旅、eureka7002模塊

啟動springBoot類栅盲、pom在eureka7001模塊基礎(chǔ)上 都不變

yaml配置文件

<pre mdtype="fences" cid="n33" lang="yaml" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> server:
port: 7002

eureka相關(guān)

eureka:
instance:
hostname: activate.navicat2.com
client:
register-with-eureka: false #是否向eureka注冊中心注冊自己
fetch-registry: false #fetch-registry為false,表示注冊中心是自己
service-url:
defaultZone: http://activate.navicat.com:7001/eureka/,http://activate.navicat3.com:7003/eureka/</pre>

四废恋、服務(wù)提供者(mySc-dept)

1谈秫、pom依賴

<pre mdtype="fences" cid="n40" lang="xml" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> <dependencies>
<dependency>
<groupId>com.gk</groupId>
<artifactId>mySc-bean</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>


<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<version>1.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies></pre>

2、yaml配置

<pre mdtype="fences" cid="n43" lang="yaml" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> server:
port: 8000

spring:
application:
name: mySc-dept
datasource:
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://localhost:3306/sales?characterEncouding&useUnicode=true&user=root&password=root
driver-class-name: com.mysql.jdbc.Driver
data-username: root
data-password: root

eureka相關(guān)

eureka:
client:
service-url:
defaultZone: http://activate.navicat.com:7001/eureka/,http://activate.navicat2.com:7002/eureka/,http://activate.navicat3.com:7003/eureka/
instance:
instance-id: mySc-provider-8000
info: # 點擊 Status 下的內(nèi)容鱼鼓,提示的內(nèi)容信息
app.name: 張三的cloud
company.name: 這是注定拟烫,這是命運</pre>

3、config包下DeptConfig配置

<pre mdtype="fences" cid="n48" lang="java" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> @Configuration
@MapperScan("com.gk.mapper")
public class DeptConfig {

}</pre>

4蚓哩、controller層DeptController

<pre mdtype="fences" cid="n53" lang="java" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gk.bean.Dept;
import com.gk.mapper.DeptMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class DeptController {
@Autowired
private DeptMapper deptMapper;
@Autowired
private DiscoveryClient client;//可以用來獲取服務(wù)信息

@RequestMapping("byId/{id}")
public Dept salById(@PathVariable Long id){
QueryWrapper<Dept> dw = new QueryWrapper<>();
dw.eq("deptno",id);
Dept dept = deptMapper.selectOne(dw);
return dept;
}
@RequestMapping("salList")
public List<Dept> salByList(){
List<Dept> depts = deptMapper.selectList(null);
return depts;
}

@RequestMapping("salByInfo")
public Object getDiscovery(){
//獲取微服務(wù)列表清單
List<String> list = client.getServices();
System.out.println(list);
System.out.println("================");
//通過微服務(wù)的Application(注冊在eureka中的實例) 獲取某個具體的微服務(wù)信息
List<ServiceInstance> instances = client.getInstances("MYSC-DEPT");//獲取mySc-dept模塊的服務(wù)信息
for (ServiceInstance s : instances) {
System.out.println(
s.getHost() + "\n"+
s.getInstanceId() + "\n"+
s.getScheme() + "\n"+
s.getServiceId() + "\n"+
s.getMetadata() + "\n"+
s.getPort() + "\n"+
s.getUri()+"\n"+
"==============="
);
}
return instances;
}
}</pre>

5、mapper接口DeptMapper

<pre mdtype="fences" cid="n59" lang="java" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> @Repository
public interface DeptMapper extends BaseMapper<Dept> {
}</pre>

6上渴、springBoot啟動類

<pre mdtype="fences" cid="n66" lang="java" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> @SpringBootApplication
@EnableEurekaClient
public class MyScDeptApplication {
public static void main(String[] args) {
SpringApplication.run(MyScDeptApplication.class,args);
}
}</pre>

五岸梨、服務(wù)提供者2和服務(wù)提供者3(mySc-dept-provider-8002)

在第一個提供者之上沒太對變化

yaml配置

<pre mdtype="fences" cid="n72" lang="yaml" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> server:
port: 8002

spring:
application:
name: mySc-dept
datasource:
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://localhost:3306/sales2?characterEncouding&useUnicode=true&user=root&password=root
driver-class-name: com.mysql.jdbc.Driver
data-username: root
data-password: root

eureka相關(guān)

eureka:
client:
service-url:
defaultZone: http://activate.navicat.com:7001/eureka/,http://activate.navicat2.com:7002/eureka/,http://activate.navicat3.com:7003/eureka/
instance:
instance-id: mySc-provider-8002
ip-address: true # 顯示服務(wù)器的ip地址
info: # 點擊 Status 下的內(nèi)容,提示的內(nèi)容信息
app.name: 張三的cloud2
company.name: 這是注定稠氮,這是命運2</pre>

<pre mdtype="fences" cid="n73" lang="yaml" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> server:
port: 8003

spring:
application:
name: mySc-dept
datasource:
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://localhost:3306/sales3?characterEncouding&useUnicode=true&user=root&password=root
driver-class-name: com.mysql.jdbc.Driver
data-username: root
data-password: root

eureka相關(guān)

eureka:
client:
service-url:
defaultZone: http://activate.navicat.com:7001/eureka/,http://activate.navicat2.com:7002/eureka/,http://activate.navicat3.com:7003/eureka/
instance:
instance-id: mySc-dept3
info: # 點擊 Status 下的內(nèi)容曹阔,提示的內(nèi)容信息
app.name: 張三的cloud3
company.name: 這是注定,這是命運3</pre>

六隔披、服務(wù)消費者()

1赃份、pom依賴

<pre mdtype="fences" cid="n81" lang="xml" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> <dependencies>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-ribbon</artifactId>
<version>1.4.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<version>1.3.4.RELEASE</version>
</dependency>

<dependency>
<groupId>com.gk</groupId>
<artifactId>mySc-bean</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
</dependencies></pre>

2、yaml配置

<pre mdtype="fences" cid="n88" lang="yaml" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> server:
port: 8001

eureka:
client:
register-with-eureka: false #不讓在eureka注冊中心注冊自己
service-url:
defaultZone: http://activate.navicat.com:7001/eureka/,http://activate.navicat2.com:7002/eureka/,http://activate.navicat3.com:7003/eureka/</pre>

3奢米、config配置(DeptConfig)

<pre mdtype="fences" cid="n91" lang="java" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> @Configuration
public class DeptConfig {
//配置負載均衡實現(xiàn)RestTemplate
@Bean
// IRule: 負載均衡策略(接口)以下為他的實現(xiàn)類
//RoundRobinRule:輪循(默認)
//RandomRule: 隨機訪問
//AvailabilityFilteringRule: 過濾掉崩潰抓韩、訪問故障、跳閘 的服務(wù)鬓长,對剩下的服務(wù)進行輪循
//RetryRule: 先按照輪循進行訪問谒拴,如果訪問失敗,會在規(guī)定的時間內(nèi) 進行重試
@LoadBalanced //使用ribbon實現(xiàn)負載均衡
public RestTemplate getRestTemplate(){
return new RestTemplate();
}
}</pre>

4涉波、controller層

<pre mdtype="fences" cid="n96" lang="java" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> @RestController
public class DeptController {
//請求前綴地址
// private final String PREFIX_URL="http://localhost:8000/";
private final String PREFIX_URL="http://MYSC-DEPT/";

@Autowired
private RestTemplate restTemplate;
@RequestMapping("salById/{id}")
public Dept salById(@PathVariable Long id){

return restTemplate.getForObject(PREFIX_URL+"byId/"+id,Dept.class);
}
@RequestMapping("salByList")
public List<Dept> salByList(){
return restTemplate.getForObject(PREFIX_URL + "salList",List.class);
}
}</pre>

5英上、springBoot啟動類

<pre mdtype="fences" cid="n99" lang="java" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> @SpringBootApplication
@EnableEurekaClient
public class MyScConsumer {
public static void main(String[] args) {
SpringApplication.run(MyScConsumer.class,args);
}
}</pre>

七、feign(負載均衡)

1啤覆、pom

<pre mdtype="fences" cid="n105" lang="xml" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> <dependencies>
<dependency>
<groupId>com.gk</groupId>
<artifactId>mySc-bean</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>


<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<version>1.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
<version>1.4.3.RELEASE</version>
</dependency>
</dependencies></pre>

2苍日、yaml配置

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="yaml" cid="n108" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> server:
port: 8005

spring:
application:
name: mySc-dept-feign
datasource:
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://localhost:3306/sales2?characterEncouding&useUnicode=true&user=root&password=root
driver-class-name: com.mysql.jdbc.Driver
data-username: root
data-password: root

eureka相關(guān)

eureka:
client:
service-url:
defaultZone: http://activate.navicat.com:7001/eureka/,http://activate.navicat2.com:7002/eureka/,http://activate.navicat3.com:7003/eureka/
instance:
instance-id: mySc-feign-8005
info: # 點擊 Status 下的內(nèi)容,提示的內(nèi)容信息
app.name: 張三的cloud2
company.name: 這是注定窗声,這是命運2</pre>

3相恃、config層

<pre mdtype="fences" cid="n103" lang="java" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> @Configuration
@ComponentScan("com.gk")
public class DeptConfig {
//配置負載均衡實現(xiàn)RestTemplate
@Bean
// IRule: 負載均衡策略(接口)一下為他的實現(xiàn)類
//RoundRobinRule:輪循(默認)
//RandomRule: 隨機訪問
//AvailabilityFilteringRule: 過濾掉崩潰、訪問故障笨觅、跳閘 的服務(wù)豆茫,對剩下的服務(wù)進行輪循
//RetryRule: 先按照輪循進行訪問侨歉,如果訪問失敗,會在規(guī)定的時間內(nèi) 進行重試
@LoadBalanced //使用ribbon實現(xiàn)
public RestTemplate getRestTemplate(){
return new RestTemplate();
}
}</pre>

4揩魂、controller層

<pre mdtype="fences" cid="n113" lang="java" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> @RestController
public class DeptController {

@Autowired
private DeptService deptService;
@RequestMapping("salById/{id}")
public Dept salById(@PathVariable(value="id") Long id){

return deptService.salById(id);
}
@RequestMapping("salByList")
public List<Dept> salByList(){
return deptService.salByList();
}
}</pre>

5幽邓、springBoot啟動類

<pre mdtype="fences" cid="n118" lang="java" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> @SpringBootApplication
@EnableEurekaClient
@EnableFeignClients(basePackages={"com.gk"})
public class FeignScConsumer {
public static void main(String[] args) {
SpringApplication.run(FeignScConsumer.class,args);
}
}</pre>

八、Hystrix(服務(wù)熔斷)

1火脉、pom

<pre mdtype="fences" cid="n122" lang="xml" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> <dependencies>
<dependency>
<groupId>com.gk</groupId>
<artifactId>mySc-bean</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>


<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<version>1.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<version>1.3.4.RELEASE</version>
</dependency>
</dependencies></pre>

2牵舵、config層

<pre mdtype="fences" cid="n125" lang="java" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> @Configuration
@MapperScan("com.gk.mapper")
public class DeptConfig {

}</pre>

3、controller層

<pre mdtype="fences" cid="n128" lang="java" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> @RestController
public class DeptController {
@Autowired
private DeptMapper deptMapper;

@RequestMapping("byId/{id}")
@HystrixCommand(fallbackMethod="salById2")//方法異常后調(diào)用salById2方法
public Dept salById(@PathVariable Long id){
QueryWrapper<Dept> dw = new QueryWrapper<>();
dw.eq("deptno",id);
Dept dept = deptMapper.selectOne(dw);
if (dept==null){
throw new RuntimeException("查詢結(jié)果為空...");
}
return dept;
}

public Dept salById2(@PathVariable Long id){
return new Dept(id,"沒有當前這個id=>"+id,"沒有這個數(shù)據(jù)庫");
}
}</pre>

4倦挂、mapper

<pre mdtype="fences" cid="n131" lang="java" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> @Repository
public interface DeptMapper extends BaseMapper<Dept> {

}</pre>

5畸颅、springBoot啟動類

<pre mdtype="fences" cid="n134" lang="java" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> @SpringBootApplication
@EnableEurekaClient
@EnableCircuitBreaker //添加熔斷支持
public class MyHystrixScDeptApplication {
public static void main(String[] args) {
SpringApplication.run(MyHystrixScDeptApplication.class,args);
}
}</pre>

6、配置文件yaml

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="yaml" cid="n137" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> server:
port: 8004

spring:
application:
name: mySc-dept
datasource:
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://localhost:3306/sales3?characterEncouding&useUnicode=true&user=root&password=root
driver-class-name: com.mysql.jdbc.Driver
data-username: root
data-password: root

eureka相關(guān)

eureka:
client:
service-url:
defaultZone: http://activate.navicat.com:7001/eureka/,http://activate.navicat2.com:7002/eureka/,http://activate.navicat3.com:7003/eureka/
instance:
instance-id: mySc-provider-hystrix-8004
info: # 點擊 Status 下的內(nèi)容方援,提示的內(nèi)容信息
app.name: 張三的cloud3
company.name: 這是注定没炒,這是命運3</pre>

九、zuul(服務(wù)路由網(wǎng)關(guān))

1犯戏、pom

<pre mdtype="fences" cid="n142" lang="xml" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> <dependencies>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
<version>1.4.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<version>1.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies></pre>

2送火、yaml配置

<pre mdtype="fences" cid="n145" lang="yaml" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> server:
port: 9527

spring 配置服務(wù)名字

spring:
application:
name: mySc-zuul-9527

eureka

eureka:
instance:
instance-id: mySc-zuul-9527
prefer-ip-address: true # 顯示id地址
client:
service-url:
defaultZone: http://activate.navicat.com:7001/eureka/,http://activate.navicat2.com:7002/eureka/,http://activate.navicat3.com:7003/eureka/
info:
app.name: zhangsan.com
app.address: www.瘋子.com
zuul:
routes:
dept.serviceId: mysc-dept
dept.path: /dept/**
ignored-services: "*" # 不允許任何一個路徑進行訪問,只允許使用 dept(http://www.gk.com:9527/dept/) 進行訪問
prefix: /gk #設(shè)置公共的訪問前綴 :http://www.gk.com:9527/gk/dept/</pre>

3先匪、springBoot啟動類

<pre mdtype="fences" cid="n148" lang="java" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> @SpringBootApplication
@EnableZuulProxy
public class MyZuulApplication {
public static void main( String[] args ){
SpringApplication.run(MyZuulApplication.class,args);
}
}</pre>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末种吸,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子呀非,更是在濱河造成了極大的恐慌坚俗,老刑警劉巖,帶你破解...
    沈念sama閱讀 211,194評論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件岸裙,死亡現(xiàn)場離奇詭異猖败,居然都是意外死亡,警方通過查閱死者的電腦和手機降允,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,058評論 2 385
  • 文/潘曉璐 我一進店門辙浑,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人拟糕,你說我怎么就攤上這事判呕。” “怎么了送滞?”我有些...
    開封第一講書人閱讀 156,780評論 0 346
  • 文/不壞的土叔 我叫張陵侠草,是天一觀的道長。 經(jīng)常有香客問我犁嗅,道長边涕,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 56,388評論 1 283
  • 正文 為了忘掉前任,我火速辦了婚禮功蜓,結(jié)果婚禮上园爷,老公的妹妹穿的比我還像新娘。我一直安慰自己式撼,他們只是感情好童社,可當我...
    茶點故事閱讀 65,430評論 5 384
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著著隆,像睡著了一般扰楼。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上美浦,一...
    開封第一講書人閱讀 49,764評論 1 290
  • 那天弦赖,我揣著相機與錄音,去河邊找鬼浦辨。 笑死蹬竖,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的流酬。 我是一名探鬼主播币厕,決...
    沈念sama閱讀 38,907評論 3 406
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼康吵!你這毒婦竟也來了劈榨?” 一聲冷哼從身側(cè)響起访递,我...
    開封第一講書人閱讀 37,679評論 0 266
  • 序言:老撾萬榮一對情侶失蹤晦嵌,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后拷姿,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體惭载,經(jīng)...
    沈念sama閱讀 44,122評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,459評論 2 325
  • 正文 我和宋清朗相戀三年响巢,在試婚紗的時候發(fā)現(xiàn)自己被綠了描滔。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 38,605評論 1 340
  • 序言:一個原本活蹦亂跳的男人離奇死亡踪古,死狀恐怖含长,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情伏穆,我是刑警寧澤拘泞,帶...
    沈念sama閱讀 34,270評論 4 329
  • 正文 年R本政府宣布,位于F島的核電站枕扫,受9級特大地震影響陪腌,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 39,867評論 3 312
  • 文/蒙蒙 一诗鸭、第九天 我趴在偏房一處隱蔽的房頂上張望染簇。 院中可真熱鬧,春花似錦强岸、人聲如沸锻弓。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,734評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽弥咪。三九已至,卻和暖如春十绑,著一層夾襖步出監(jiān)牢的瞬間聚至,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,961評論 1 265
  • 我被黑心中介騙來泰國打工本橙, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留扳躬,地道東北人。 一個月前我還...
    沈念sama閱讀 46,297評論 2 360
  • 正文 我出身青樓甚亭,卻偏偏與公主長得像贷币,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子亏狰,可洞房花燭夜當晚...
    茶點故事閱讀 43,472評論 2 348

推薦閱讀更多精彩內(nèi)容

  • SpringCloud: SpringCloud是關(guān)注全局的微服務(wù)協(xié)調(diào)整理框架役纹,他將SpringBoot開發(fā)的一個...
    成林的世界閱讀 327評論 1 1
  • 一. SpringCloud參考資料 官網(wǎng) http://projects.spring.io/spring-cl...
    H同學_閱讀 251評論 0 1
  • 英語好的可以看官方文檔:Spring Cloud Config 中文版:Spring Cloud Config S...
    zero_93a5閱讀 414評論 0 0
  • 一促脉、概述 1、分布式系統(tǒng)面臨的配置問題 ? 微服務(wù)意味著要將單體應(yīng)用中的業(yè)務(wù)拆分成一個個子服務(wù)策州,每個服務(wù)的粒度相對...
    神奇作手閱讀 312評論 0 0
  • 16宿命:用概率思維提高你的勝算 以前的我是風險厭惡者瘸味,不喜歡去冒險,但是人生放棄了冒險够挂,也就放棄了無數(shù)的可能旁仿。 ...
    yichen大刀閱讀 6,038評論 0 4