• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

springboot 搞代码 4年前 (2022-01-05) 39次浏览 已收录 0个评论

这篇文章主要介绍了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<em style="color:transparent">来源[email protected]搞@^&代*@码)网</em>"), @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刚出没多久,所以这块资料网上很少,查阅资料说是新版本中不包含此注解了,需要重新引入。

报错信息:

源码:

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

  com.netflix.hystrixhystrix-javanicaRELEASE

完整pom.xml

   4.0.0com.serverribbonserverribbon0.0.1-SNAPSHOTjarserverribbonDemo project for Spring Boot org.springframework.bootspring-boot-starter-parent2.0.2.RELEASE<!-- lookup parent from repository --> UTF-UTF-1.8Finchley.RC2  org.springframework.cloudspring-cloud-starter-netflix-eureka-server org.springframework.cloudspring-cloud-starter-ribbon org.springframework.cloudspring-cloud-starter-hystrix com.netflix.hystrixhystrix-javanicaRELEASE org.springframework.bootspring-boot-starter-testtest com.netflix.hystrixhystrix-coreRELEASE com.netflix.hystrixhystrix-coreRELEASE   org.springframework.cloudspring-cloud-dependencies${spring-cloud.version}pomimport   org.springframework.bootspring-boot-maven-plugin  spring-milestonesSpring Milestoneshttps://repo.spring.io/milestone false

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

以上就是SpringBoot2.0整合SpringCloud Finchley @hystrixcommand注解找不到解决方案的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:SpringBoot2.0整合SpringCloud Finchley @hystrixcommand注解找不到解决方案

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址