网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

SpringBoot2.0整合SpringCloudFinchley@hystrixcommand注解找不到怎么办

这篇文章给大家分享的是有关SpringBoot2.0整合SpringCloud Finchley @hystrixcommand注解找不到怎么办的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

成都创新互联是创新、创意、研发型一体的综合型网站建设公司,自成立以来公司不断探索创新,始终坚持为客户提供满意周到的服务,在本地打下了良好的口碑,在过去的10余年时间我们累计服务了上千家以及全国政企客户,如成都格栅板等企业单位,完善的项目管理流程,严格把控项目进度与质量监控加上过硬的技术实力获得客户的一致赞誉。

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);
}

/**
* fallback方法
* @param id
* @return
*/
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刚出没多久,所以这块资料网上很少,查阅资料说是新版本中不包含此注解了,需要重新引入。

报错信息:

SpringBoot2.0整合SpringCloud Finchley @hystrixcommand注解找不到怎么办

源码:

SpringBoot2.0整合SpringCloud Finchley @hystrixcommand注解找不到怎么办

SpringBoot2.0整合SpringCloud Finchley @hystrixcommand注解找不到怎么办

SpringBoot2.0整合SpringCloud Finchley @hystrixcommand注解找不到怎么办

解决方案: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

感谢各位的阅读!关于“SpringBoot2.0整合SpringCloud Finchley @hystrixcommand注解找不到怎么办”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!


本文名称:SpringBoot2.0整合SpringCloudFinchley@hystrixcommand注解找不到怎么办
文章源于:http://bjjierui.cn/article/pjhhds.html

其他资讯