spring-boot-starter-openfeign

An auto configure library for projects relied on Spring Boot to easily generate openfeign clients without using Eureka

License

License

Categories

Categories

Spring Boot Container Microservices Feign Net HTTP Clients
GroupId

GroupId

com.github.ethancommitpush
ArtifactId

ArtifactId

spring-boot-starter-openfeign
Last Version

Last Version

1.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

spring-boot-starter-openfeign
An auto configure library for projects relied on Spring Boot to easily generate openfeign clients without using Eureka
Project URL

Project URL

https://github.com/ethancommitpush/spring-boot-starter-openfeign
Source Code Management

Source Code Management

https://github.com/ethancommitpush/spring-boot-starter-openfeign/tree/master

Download spring-boot-starter-openfeign

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.ethancommitpush/spring-boot-starter-openfeign/ -->
<dependency>
    <groupId>com.github.ethancommitpush</groupId>
    <artifactId>spring-boot-starter-openfeign</artifactId>
    <version>1.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.ethancommitpush/spring-boot-starter-openfeign/
implementation 'com.github.ethancommitpush:spring-boot-starter-openfeign:1.2.0'
// https://jarcasting.com/artifacts/com.github.ethancommitpush/spring-boot-starter-openfeign/
implementation ("com.github.ethancommitpush:spring-boot-starter-openfeign:1.2.0")
'com.github.ethancommitpush:spring-boot-starter-openfeign:jar:1.2.0'
<dependency org="com.github.ethancommitpush" name="spring-boot-starter-openfeign" rev="1.2.0">
  <artifact name="spring-boot-starter-openfeign" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.ethancommitpush', module='spring-boot-starter-openfeign', version='1.2.0')
)
libraryDependencies += "com.github.ethancommitpush" % "spring-boot-starter-openfeign" % "1.2.0"
[com.github.ethancommitpush/spring-boot-starter-openfeign "1.2.0"]

Dependencies

compile (6)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.28
org.springframework.boot : spring-boot-autoconfigure jar 2.2.0.RELEASE
io.github.openfeign : feign-core jar 10.7.3
io.github.openfeign : feign-jackson jar 10.7.3
io.github.openfeign : feign-httpclient jar 10.7.3
io.github.openfeign : feign-slf4j jar 10.7.3

test (1)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-test jar 2.2.0.RELEASE

Project Modules

There are no modules declared in this project.

Maven Central

Spring Boot Starter OpenFeign

This library makes it easier to automatically use Feign.builder() to construct API interfaces with your custom components declared with a @FeignClient annotation. There is no any configures about Ribbon or Eureka for this library, just simply visits the APIs with the domain URL and path.

Artifacts

What's New?

1.2.0 - 25th January 2021

  • Enhance the @FeignClient annotation customizations including fully configurable HTTP client, request encoder, response decoder, and error response decoder
  • Enhance the properties file customizations including configurable logLevel and loggerType

1.1.3 - 9th January 2021

  • Fix CustomErrorDecoder error and upgrade to compatible with feign ^10.7.3 ~10.12

Requirements

The following table shows the feign versions that are used by version of spring-boot-starter-openfeign:

spring-boot-starter-openfeign feign
1.2.0
1.1.3
^10.7.3
1.1.2 10.7.2

Maven Configuration

Add the Maven dependency:

<dependency>
  <groupId>com.github.ethancommitpush</groupId>
  <artifactId>spring-boot-starter-openfeign</artifactId>
  <version>1.2.0</version>
</dependency>

<dependency>
  <groupId>io.github.openfeign</groupId>
  <artifactId>feign-core</artifactId>
  <version>10.7.3</version>
</dependency>

<dependency>
  <groupId>io.github.openfeign</groupId>
  <artifactId>feign-jackson</artifactId>
  <version>10.7.3</version>
</dependency>

<dependency>
  <groupId>io.github.openfeign</groupId>
  <artifactId>feign-httpclient</artifactId>
  <version>10.7.3</version>
</dependency>

<dependency>
  <groupId>io.github.openfeign</groupId>
  <artifactId>feign-slf4j</artifactId>
  <version>10.7.3</version>
</dependency>

Gradle

compile group: 'com.github.ethancommitpush', name: 'spring-boot-starter-openfeign', version: '1.2.0'
compile group: 'io.github.openfeign', name: 'feign-core', version: '10.7.3'
compile group: 'io.github.openfeign', name: 'feign-jackson', version: '10.7.3'
compile group: 'io.github.openfeign', name: 'feign-httpclient', version: '10.7.3'
compile group: 'io.github.openfeign', name: 'feign-slf4j', version: '10.7.3'

Basic Usage

  • Use @FeignClient to declare custom components to be generated as API interfaces:
package example.client;

@Headers({"Content-Type: application/json"})
@FeignClient(url = "${postman-echo.domain}")
public interface PostmanEchoClient {

    @RequestLine("GET /time/object?timestamp={timestamp}")
    TimeObjectGetRespDTO getTimeObject(@Param("timestamp") String timestamp);

}
  • application.yml Properties configuration:
feign:
  # Set up log level for feign behaviors
  log-level: BASIC
  # Set up logger type to append logs
  logger-type: SLF4J
  # Packages to be scanned for interfaces declared with @FeignClient
  base-packages: example.client

postman-echo:
  # The base url for your API interface, e. g. @FeignClient(url = "${postman-echo.domain}")
  domain: https://postman-echo.com
  • Use @Autowired to autowire the API interfaces and further use it:
    @Autowired
    private PostmanEchoClient postmanEchoClient;

    public void run(String... args) throws Exception {
        TimeObjectGetRespDTO respDTO1 = postmanEchoClient.getTimeObject("2016-10-10");
        log.info("{}", respDTO1);
    }

Examples

Look up the example.

Advanced Usage

  • The following table shows the components and iots default bean names which were used by spring-boot-starter-openfeign. If you want to customize some components of them, just implement the component interfaces and delare them as beans:
Component Type Default Bean Name Component Interface
HTTP Client feignClient feign.Client
Request Encoder feignEncoder feign.codec.Encoder
Response Decoder feignDecoder feign.codec.Decoder
Error Response Decoder feignErrorDecoder feign.codec.ErrorDecoder
  • Use @Configuration to declare a default decoder for all API interfaces with @FeignClient annotation:
@Configuration
@Slf4j
public class FeignConfig {
    @Bean
    public Decoder feignDecoder() {
        return new JacksonDecoder() {
            @Override
            public Object decode(Response response, Type type) throws IOException {
                log.info("inside overridden feignDecoder.decoder()");
                return super.decode(response, type);
            }
        };
    }
}
  • Use @Configuration to declare a custom decoder, and assign to certain API interface with @FeignClient annotation:
@Configuration
@Slf4j
public class FeignConfig {
    @Bean
    public Decoder myDecoder() {
        return new JacksonDecoder() {
            @Override
            public Object decode(Response response, Type type) throws IOException {
                log.info("inside myDecoder.decoder()");
                return super.decode(response, type);
            }
        };
    }
}
@FeignClient(url = "${postman-echo.domain}", decoder = "myDecoder")
public interface PostmanEchoClient2 {

    @RequestLine("POST /post?foo1={foo1}&foo2={foo2}")
    PostPostRespDTO postPost(@Param("foo1") String foo1, @Param("foo2") String foo2);

}

Versions

Version
1.2.0
1.1.3
1.1.2
1.1.0
1.0.0