栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SpringBoot2.0整合SpringCloud Finchley @hystrixcommand注解找不到解决方案

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SpringBoot2.0整合SpringCloud Finchley @hystrixcommand注解找不到解决方案

hystrix参数使用方法

通过注解@HystrixCommand的commandProperties去配置,

如下就是hystrix命令超时时间命令执行超时时间,为1000ms和执行是不启用超时

@RestController
public class MovieController {
@Autowired
private RestTemplate restTemplate;

@GetMapping("/movie/{id}")
@HystrixCommand(commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1000"),
@HystrixProperty(name = "execution.timeout.enabled", value = "false")},fallbackMethod = "findByIdFallback")
public User findById(@PathVariable Long id) {
return this.restTemplate.getForObject("http://microservice-provider-user/simple/" + id, User.class);
}


public User findByIdFallback(Long id) {
User user = new User();
user.setId(5L);
return user;
}
}

问题描述:

笔者在使用Spring Boot 2.0整合Spring Cloud Finchley.RC2版本时,使用断路器 Hystrix时候发现@hystrixcommand注解找不到,由于Spring Boot 2.0刚出没多久,所以这块资料网上很少,查阅资料说是新版本中不包含此注解了,需要重新引入。

报错信息:


源码:

解决方案:pom.xml添加依赖


 com.netflix.hystrix
  hystrix-javanica
  RELEASE


完整pom.xml



  4.0.0
  com.serverribbon
  serverribbon
  0.0.1-SNAPSHOT
  jar
 
  serverribbon
  Demo project for Spring Boot
 
  
   org.springframework.boot
   spring-boot-starter-parent
   2.0.2.RELEASE
    
  
 
  
   UTF-
   UTF-
   1.8
   Finchley.RC2
  
 
  
   
     org.springframework.cloud
     spring-cloud-starter-netflix-eureka-server
   
 
   
     org.springframework.cloud
     spring-cloud-starter-ribbon
   
 
   
     org.springframework.cloud
     spring-cloud-starter-hystrix
   
 
   
     com.netflix.hystrix
     hystrix-javanica
     RELEASE
   
 
   
     org.springframework.boot
     spring-boot-starter-test
     test
   
   
     com.netflix.hystrix
     hystrix-core
     RELEASE
   
    
      com.netflix.hystrix
      hystrix-core
      RELEASE
    
  
 
  
   
     
      org.springframework.cloud
      spring-cloud-dependencies
      ${spring-cloud.version}
      pom
      import
     
   
  
 
  
   
     
      org.springframework.boot
      spring-boot-maven-plugin
     
   
  
 
  
   
     spring-milestones
     Spring Milestones
     https://repo.spring.io/milestone
     
      false
     
   
  
 
 

在程序的启动类ServiceRibbonApplication 加@EnableHystrix注解开启Hystrix

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/140133.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号