欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2018年08月27日 15:03:14   作者:zjh_746140129  
這篇文章主要介紹了SpringBoot2.0整合SpringCloud Finchley @hystrixcommand注解找不到解決方案,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

hystrix參數(shù)使用方法

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

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

@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時候發(fā)現(xiàn)@hystrixcommand注解找不到,由于Spring Boot 2.0剛出沒多久,所以這塊資料網(wǎng)上很少,查閱資料說是新版本中不包含此注解了,需要重新引入。

報錯信息:


源碼:

解決方案:pom.xml添加依賴

<dependency>
 <groupId>com.netflix.hystrix</groupId>
  <artifactId>hystrix-javanica</artifactId>
  <version>RELEASE</version>
</dependency>

完整pom.xml

<?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

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • java方法通用返回結果集封裝操作

    java方法通用返回結果集封裝操作

    這篇文章主要介紹了java方法通用返回結果集封裝操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-08-08
  • Java字符編碼原理(動力節(jié)點Java學院整理)

    Java字符編碼原理(動力節(jié)點Java學院整理)

    Java開發(fā)中,常常會遇到亂碼的問題,一旦遇到這種問題,常常比較煩惱,大家都不想承認是自己的代碼問題,其實搞明白編碼的本質(zhì)過程就簡單多了,接下來小編給大家?guī)韏ava字符編碼原理,要求看看吧
    2017-04-04
  • Filter中獲取傳遞參數(shù)方式(解決post請求參數(shù)問題)

    Filter中獲取傳遞參數(shù)方式(解決post請求參數(shù)問題)

    這篇文章主要介紹了Filter中獲取傳遞參數(shù)方式(解決post請求參數(shù)問題),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-08-08
  • Java?MyBatis本地緩存原理詳解

    Java?MyBatis本地緩存原理詳解

    這篇文章主要介紹了Java?MyBatis本地緩存原理詳解,文章圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下
    2022-07-07
  • Log4j.properties配置及其使用

    Log4j.properties配置及其使用

    本文主要介紹了Log4j.properties配置及其使用,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • MyBatis映射文件中的動態(tài)SQL實例詳解

    MyBatis映射文件中的動態(tài)SQL實例詳解

    在本文中,我們深入探討了動態(tài)SQL的各種標簽,包括<if>、<choose>、<trim>、<foreach>等,通過實際的例子演示了它們的用法,感興趣的朋友一起揭開動態(tài)SQL的神秘面紗,帶你領略它的魅力
    2024-01-01
  • Java日常練習題,每天進步一點點(56)

    Java日常練習題,每天進步一點點(56)

    下面小編就為大家?guī)硪黄狫ava基礎的幾道練習題(分享)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧,希望可以幫到你
    2021-08-08
  • Java數(shù)組反轉方式

    Java數(shù)組反轉方式

    這篇文章主要介紹了Java數(shù)組反轉方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-06-06
  • 一篇文章帶了解如何用SpringBoot在RequestBody中優(yōu)雅的使用枚舉參數(shù)

    一篇文章帶了解如何用SpringBoot在RequestBody中優(yōu)雅的使用枚舉參數(shù)

    這篇文章主要介紹了SpringBoot中RequestBodyAdvice使用枚舉參數(shù),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-08-08
  • 基于UDP協(xié)議實現(xiàn)聊天系統(tǒng)

    基于UDP協(xié)議實現(xiàn)聊天系統(tǒng)

    這篇文章主要為大家詳細介紹了基于UDP協(xié)議實現(xiàn)聊天系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-04-04

最新評論