Spring-cloud-eureka使用feign調(diào)用服務(wù)接口
Spring-cloud-eureka使用feign調(diào)用服務(wù)接口的具體方法,供大家參考,具體內(nèi)容如下
基于spring-boot 2.0以上版本完成的微服務(wù)架構(gòu)
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.SR1</spring-cloud.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-core</artifactId>
<version>2.0.1.RELEASE</version>
<classifier>sources</classifier>
<type>java-source</type>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.39</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.20</version>
<optional>true</optional>
</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>
feignClient
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
/*
* @version 1.0 created by carolon 2018/9/25 17:18
*/
@FeignClient(value = "服務(wù)名")
public interface FeignClient {
@RequestMapping(method = RequestMethod.POST, value = "接口地址")
String sendDebugInfo(Object debugInfo);
}
finally
直接在需要的地方注入該client然后調(diào)用即可
@Autowired private FeignService feignService;
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
java中字符進(jìn)行全角半角轉(zhuǎn)換示例代碼
全角:指一個(gè)字符占用兩個(gè)標(biāo)準(zhǔn)字符位置,而半角:指一字符占用一個(gè)標(biāo)準(zhǔn)的字符位置,在日常開發(fā)中經(jīng)常會(huì)遇到全角半角轉(zhuǎn)換的要求,下面這篇文章主要給大家介紹了關(guān)于java中字符進(jìn)行全角半角轉(zhuǎn)換的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下。2017-08-08
JAVA實(shí)現(xiàn)用戶抽獎(jiǎng)功能(附完整代碼)
這篇文章主要給大家介紹了關(guān)于JAVA實(shí)現(xiàn)用戶抽獎(jiǎng)功能的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11
Java并發(fā)編程線程間通訊實(shí)現(xiàn)過程詳解
這篇文章主要介紹了Java并發(fā)編程線程間通訊實(shí)現(xiàn)過程詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-05-05
談?wù)凧ava中Volatile關(guān)鍵字的理解
volatile這個(gè)關(guān)鍵字可能很多朋友都聽說過,或許也都用過。在Java 5之前,它是一個(gè)備受爭議的關(guān)鍵字,因?yàn)樵诔绦蛑惺褂盟鶗?huì)導(dǎo)致出人意料的結(jié)果,本文給大家介紹java中volatile關(guān)鍵字,需要的朋友參考下2016-03-03
Spring多線程通過@Scheduled實(shí)現(xiàn)定時(shí)任務(wù)
這篇文章主要介紹了Spring多線程通過@Scheduled實(shí)現(xiàn)定時(shí)任務(wù),@Scheduled?定時(shí)任務(wù)調(diào)度注解,是spring定時(shí)任務(wù)中最重要的,下文關(guān)于其具體介紹,需要的小伙伴可以參考一下2022-05-05

