spring-boot-starter-openfeign

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

Лицензия

Лицензия

Категории

Категории

Spring Boot Контейнер Микросервисы Feign Сеть HTTP Clients
Группа

Группа

com.github.ethancommitpush
Идентификатор

Идентификатор

spring-boot-starter-openfeign
Последняя версия

Последняя версия

1.2.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

spring-boot-starter-openfeign
An auto configure library for projects relied on Spring Boot to easily generate openfeign clients without using Eureka
Ссылка на сайт

Ссылка на сайт

https://github.com/ethancommitpush/spring-boot-starter-openfeign
Система контроля версий

Система контроля версий

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

Скачать spring-boot-starter-openfeign

Как подключить последнюю версию

<!-- 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"]

Зависимости

compile (6)

Идентификатор библиотеки Тип Версия
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)

Идентификатор библиотеки Тип Версия
org.springframework.boot : spring-boot-starter-test jar 2.2.0.RELEASE

Модули Проекта

Данный проект не имеет модулей.

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);

}

Версии библиотеки

Версия
1.2.0
1.1.3
1.1.2
1.1.0
1.0.0