Aprende de la estación b springcloud, ahora resumir la expulsión sumaria de un pequeño error que aparece en el video, algunos de los lugares propensos a errores se recordó
b enlaces salientes: https://www.bilibili.com/video/av55304977
de enlace de datos:
https://pan.baidu.com/s/1o0Aju3IydKA15Vo1pP4z5w
código de extracción: 21ru
En un enlace: https://blog.csdn.net/qq_40893824/article/details/103336449
La siguiente lista resume: interfaces de sub-proyecto → → pom aplicación → → → manejador de clase entidad → inicio de clases
Los detalles de implementación:
1. Crear un módulo de módulo, llamado hystrix
2. fichero POM del módulo, agregue el código:
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
</dependencies>
3. application.yml Chong en recursos, añadir código:
server:
port: 8060
spring:
application:
name: hystrix
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
instance:
prefer-ip-address: true
feign:
hystrix:
enabled: true
management:
endpoints:
web:
exposure:
include: 'hystrix.stream'
4. En java com.southwind Registro de paquete, creando HystrixApplication.java clase de inicio viento del sur, rellene el código:
package com.southwind;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableFeignClients
@EnableCircuitBreaker
@EnableHystrixDashboard
/*
@EnableCircuitBreaker:声明启用数据监控
@EnableHystrixDashboard:声明启用可视化数据监控
*/
public class HystrixApplication {
public static void main(String[] args) {
SpringApplication.run(HystrixApplication.class,args);
}
}
5.southwind entidad siguiente paquete de registro, a la que la replicación del Estudiante
crear paquetes fingen bajo 6.southwind, la creación de interfaces: FeignProviderClient
package com.southwind.feign;
import com.southwind.entity.Student;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.Collection;
@FeignClient(value = "provider")
public interface FeignProviderClient {
//声明接口
@GetMapping("/student/findAll")
public Collection<Student> findAll();
@GetMapping("/student/index")
public String index();
}
7. El registro en el paquete controlador de viento del sur, crear FeignHandler.java
código de complemento:
package com.southwind.controller;
import com.southwind.entity.Student;
import com.southwind.feign.FeignProviderClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collection;
@RestController
@RequestMapping("/hystrix")
public class HystrixHandler {
@Autowired
private FeignProviderClient feignProviderClient;
@GetMapping("/findAll")
public Collection<Student> findAll(){
return feignProviderClient.findAll();
}
@GetMapping("/index")
public String index(){
return feignProviderClient.index();
}
}
8. Comprobar:
entrar en http: // localhost: 8060 / actuador / hystrix.stream
entrar en http: // localhost: 8060 / hystrix / index
también encontró http: // localhost: 8060 / actuador / hystrix.stream en:
interfaces visuales:
http: // localhost: 8060 / hystrix
En un enlace: https://blog.csdn.net/qq_40893824/article/details/103336449