一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - SpringBoot2.0整合SpringCloud Finchley @hystrixcommand注解找不到解決方案

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

2021-05-28 13:19zjh_746140129 Java教程

這篇文章主要介紹了SpringBoot2.0整合SpringCloud Finchley @hystrixcommand注解找不到解決方案,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

hystrix參數使用方法

通過注解@hystrixcommand的commandproperties去配置,

如下就是hystrix命令超時時間命令執行超時時間,為1000ms和執行是不啟用超時

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
@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添加依賴

?
1
2
3
4
5
<dependency>
 <groupid>com.netflix.hystrix</groupid>
  <artifactid>hystrix-javanica</artifactid>
  <version>release</version>
</dependency>

完整pom.xml

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"
  xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelversion>4.0.0</modelversion>
  <groupid>com.serverribbon</groupid>
  <artifactid>serverribbon</artifactid>
  <version>0.0.1-snapshot</version>
  <packaging>jar</packaging>
 
  <name>serverribbon</name>
  <description>demo project for spring boot</description>
 
  <parent>
   <groupid>org.springframework.boot</groupid>
   <artifactid>spring-boot-starter-parent</artifactid>
   <version>2.0.2.release</version>
   <relativepath/> <!-- lookup parent from repository -->
  </parent>
 
  <properties>
   <project.build.sourceencoding>utf-</project.build.sourceencoding>
   <project.reporting.outputencoding>utf-</project.reporting.outputencoding>
   <java.version>1.8</java.version>
   <spring-cloud.version>finchley.rc2</spring-cloud.version>
  </properties>
 
  <dependencies>
   <dependency>
     <groupid>org.springframework.cloud</groupid>
     <artifactid>spring-cloud-starter-netflix-eureka-server</artifactid>
   </dependency>
 
   <dependency>
     <groupid>org.springframework.cloud</groupid>
     <artifactid>spring-cloud-starter-ribbon</artifactid>
   </dependency>
 
   <dependency>
     <groupid>org.springframework.cloud</groupid>
     <artifactid>spring-cloud-starter-hystrix</artifactid>
   </dependency>
 
   <dependency>
     <groupid>com.netflix.hystrix</groupid>
     <artifactid>hystrix-javanica</artifactid>
     <version>release</version>
   </dependency>
 
   <dependency>
     <groupid>org.springframework.boot</groupid>
     <artifactid>spring-boot-starter-test</artifactid>
     <scope>test</scope>
   </dependency>
   <dependency>
     <groupid>com.netflix.hystrix</groupid>
     <artifactid>hystrix-core</artifactid>
     <version>release</version>
   </dependency>
    <dependency>
      <groupid>com.netflix.hystrix</groupid>
      <artifactid>hystrix-core</artifactid>
      <version>release</version>
    </dependency>
  </dependencies>
 
  <dependencymanagement>
   <dependencies>
     <dependency>
      <groupid>org.springframework.cloud</groupid>
      <artifactid>spring-cloud-dependencies</artifactid>
      <version>${spring-cloud.version}</version>
      <type>pom</type>
      <scope>import</scope>
     </dependency>
   </dependencies>
  </dependencymanagement>
 
  <build>
   <plugins>
     <plugin>
      <groupid>org.springframework.boot</groupid>
      <artifactid>spring-boot-maven-plugin</artifactid>
     </plugin>
   </plugins>
  </build>
 
  <repositories>
   <repository>
     <id>spring-milestones</id>
     <name>spring milestones</name>
     <url>https://repo.spring.io/milestone</url>
     <snapshots>
      <enabled>false</enabled>
     </snapshots>
   </repository>
  </repositories>
 
 
</project>

在程序的啟動類serviceribbonapplication 加@enablehystrix注解開啟hystrix

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

原文鏈接:https://blog.csdn.net/zjh_746140129/article/details/80697921

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 女教师雪白老汉 | 日韩欧美一级大片 | 公交车高h | 国产91第一页 | 日本乱中文字幕系列在线观看 | 男人综合网 | freexxx性欧美3d动漫 | 美女被无套进入 | 性夜影院午夜看片 | 被强迫变性翘秘书 | 免费看www| 国产肥女bbwbbw | 国产夜趣福利第一视频 | 韩国女主播在线大尺无遮挡 | 欧美一级欧美一级高清 | 国产拍拍视频一二三四区 | 成年人视频在线 | 国产最强大片免费视频 | 国产成人免费视频 | 亚洲精品91香蕉综合区 | 韩国久播影院理论片不卡影院 | 石原莉奈被店长侵犯免费 | 亚洲欧美国产另类视频 | 视频一区在线免费观看 | 任你操视频在线观看 | 色老板视频在线 | 国产免费久久精品 | 欧美日本一道高清二区三区 | 91xj视频| 国产亚洲精品一区久久 | 四虎影视库永久在线地址 | 免费视频片在线观看 | 国产伦精品一区二区 | 99久久精品免费看国产一区 | 亚洲欧美日韩国产精品影院 | 忘忧草秋观看未满十八 | 成年人在线播放视频 | 国产美女亚洲精品久久久综合91 | 久久AV国产麻豆HD真实乱 | 男同互操 | 91网站入口 |