2

According to the documentation, for activating the cricuit breaker I have to add feign.circuitbreaker.enabled=true in the properties.

It's working but I'd like to find a way of activating with an annotation.

I tried something like

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-circuitbreaker-resilience4j</artifactId>
</dependency>

and

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@EnableFeignClients
public @interface EnableFeign {
}

and

@Configuration
@EnableFeign
public class FeignConfiguration {
    public FeignConfiguration() {
        Properties properties = System.getProperties();
        properties.setProperty("feign.circuitbreaker.enabled", "true");
    }

}

But it is not working. It seems the property is set after EnableFeignClients is initialized and I got an exception

Cannot invoke "org.springframework.cloud.openfeign.CircuitBreakerNameResolver.resolveCircuitBreakerName(String, feign.Target, java.lang.reflect.Method)" because "this.circuitBreakerNameResolver" is null]

After a 'hot reload' in Intellij, it is working because the property remains.

So it's the the way to do. And I'd also prefered having just an annotation and not the constructor int the FeignConfiguration

Is there a way of do like that and having it working ?

tweetysat
  • 2,187
  • 14
  • 38
  • 75

1 Answers1

0

How did you create feign ?

Feign.builder() OR FeignCircuitBreaker.builder() ?

Using the 'FeignCircuitBreaker.builder()' will get exception.

zy_sun
  • 175
  • 1
  • 11