mysql连接测试不成功的原因有哪些
235
2023-07-21
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);
}
/**
* 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注解找不到,由于SJcvwsqLpring Boot 2.0刚出没多久,所以这块资料网上很少,查阅资料说是新版本中不包含此注解了,需要重新引入。
报错信息:
源码:
解决方案:pom.xml添加依赖
完整pom.xml
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
在程序的启动类ServiceRibbonApplication 加@EnableHystrix注解开启Hystrix
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~