Spring-cloud-eureka使用feign调用服务接口
程序员文章站
2023-12-11 19:11:04
spring-cloud-eureka使用feign调用服务接口的具体方法,供大家参考,具体内容如下
基于spring-boot 2.0以上版本完成的微服务架构
pom...
spring-cloud-eureka使用feign调用服务接口的具体方法,供大家参考,具体内容如下
基于spring-boot 2.0以上版本完成的微服务架构
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 = "服务名") public interface feignclient { @requestmapping(method = requestmethod.post, value = "接口地址") string senddebuginfo(object debuginfo); }
finally
直接在需要的地方注入该client然后调用即可
@autowired private feignservice feignservice;
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。