Feign【@FeignClient】

First look at @FeignClient annotated source code:

package org.springframework.cloud.openfeign;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.core.annotation.AliasFor;

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface FeignClient {
    @AliasFor("name")
    String value() default "";

    /** @deprecated */
    @Deprecated
    String serviceId() default "";

    @AliasFor("value")
    String name() default "";

    String qualifier() default "";

    String url() default "";

    boolean decode404() default false;

    Class<?>[] configuration() default {};

    Class<?> fallback() default void.class;

    Class<?> fallbackFactory() default void.class;

    String path() default "";

    boolean primary() default true;
}

It can be seen @FeignClient annotations are @Target (ElementType.TYPE) modified annotation indicates @FeignClient target acting on the interface.

Summarized as follows for their common attributes:

  • String name (): Specifies the name of FeignClient if the project uses ribbon to do load balancing, name attribute as the name of the micro-services, for service discovery.
  • String url (): url generally used for debugging, you can specify the address FeignClient annotation call.
  • boolean decode404 (): when a 404 error occurs if the field is true, it calls the decoder decodes FeignException otherwise throw an exception, the default is false.
  • Class configuration () <?>: Feign configuration class, you can customize Feign the Encoder, Decoder, LogLevel, Contract.
  • Class fallback () <?>: Fault tolerant process defined class, when the remote call out or remote interface failure, fault tolerance logic will invoke a corresponding interface, fallback specified class must implement the interface @FeignClient labeled.
  • Class fallbackFactory () <?>: Factory class, for generating a fallback class instances, we can achieve this property by the interface logic of each generic fault tolerance, reducing code duplication.
  • String path (): the definition of a unified prefix path for current FeignClient.

Guess you like

Origin www.cnblogs.com/idoljames/p/11668598.html
Recommended