title: Error 302 Using FeignClient in Spring Boot Microservices
body: <p>I have a problem with FeignClient. I am deployed Spring Boot applications, I get an error in a call to a specific feign client, the error comes up when I use a registration microservice when wanting to communicate with a specific method of a user microservice, with other methods the problem does not occur, I also have a Eureka server for discovery and a gateway with Spring Cloud Gateway, configured with the configuration for permissions. I have @EnableEurekaClient and @EnableFeignClients in applications and they can be seen on the Eureka server, and implements CircuitBreaker with resilience4j.
  For testing I use postman.</p>
  <p>for a request:</p>
  <p><a href="https://i.stack.imgur.com/b2txq.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/b2txq.jpg" alt="postman request" /></a></p>
  <p>Without CircuitBreaker I get this error</p>
  <pre><code>feign.FeignException: [302] during [GET] to [http://app-usuarios/users/usuarioExisteDatos/?username=admin&amp;email=admin%40udea.edu.co&amp;cellPhone=3128211358] [UsersFeignClient#preguntarUsuarioExiste(String,String,String)]: true
  at feign.FeignException.errorStatus(FeignException.java:182) ~[feign-core-10.12.jar:na]
  at feign.FeignException.errorStatus(FeignException.java:169) ~[feign-core-10.12.jar:na]
  at feign.codec.ErrorDecoder$Default.decode(ErrorDecoder.java:92) ~[feign-core-10.12.jar:na]
  at feign.AsyncResponseHandler.handleResponse(AsyncResponseHandler.java:96) ~[feign-core-10.12.jar:na]
  at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:138) ~[feign-core-10.12.jar:na]
  at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:89) ~[feign-core-10.12.jar:na]
  at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:100) ~[feign-core-10.12.jar:na]
  at jdk.proxy11/jdk.proxy11.$Proxy250.preguntarUsuarioExiste(Unknown Source) ~[na:na]
  at com.app.registro.controllers.RegistroController.crearNuevo(RegistroController.java:28) ~[classes/:na]
  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78) ~[na:na]
  at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
  at java.base/java.lang.reflect.Method.invoke(Method.java:567) ~[na:na]
  at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-5.3.13.jar:5.3.13]
  at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) ~[spring-web-5.3.13.jar:5.3.13]
  at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) ~[spring-webmvc-5.3.13.jar:5.3.13]
  at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.3.13.jar:5.3.13]
  at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.13.jar:5.3.13]
  at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.3.13.jar:5.3.13]
  at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067) ~[spring-webmvc-5.3.13.jar:5.3.13]
  at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) ~[spring-webmvc-5.3.13.jar:5.3.13]
  at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.13.jar:5.3.13]
  at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.3.13.jar:5.3.13]
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:681) ~[tomcat-embed-core-9.0.55.jar:4.0.FR]
  at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.3.13.jar:5.3.13]
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) ~[tomcat-embed-core-9.0.55.jar:4.0.FR]
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
  at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.55.jar:9.0.55]
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
  at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.3.13.jar:5.3.13]
  at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.13.jar:5.3.13]
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
  at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.3.13.jar:5.3.13]
  at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.13.jar:5.3.13]
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
  at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.3.13.jar:5.3.13]
  at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.13.jar:5.3.13]
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
  at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
  at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
  at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:895) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
  at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1722) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
  at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
  at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
  at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
  at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.55.jar:9.0.55]
  at java.base/java.lang.Thread.run(Thread.java:831) ~[na:na]
  </code></pre>
  <p>With CircuitBreaker:</p>
  <pre><code>[302] during [GET] to [http://app-usuarios/users/usuarioExisteDatos/?username=admin&amp;email=admin%40udea.edu.co&amp;cellPhone=3128211358] [UsersFeignClient#preguntarUsuarioExiste(String,String,String)]: [true]
  </code></pre>
  <p>for my registro microservice:</p>
  <p>Model:</p>
  <pre><code>@Document(collection = &quot;registro&quot;)
  public class Registro {
  
      @Id
      private String id;
  
      @NotBlank(message = &quot;Username cannot be null&quot;)
      @Size(max = 20)
      @Indexed(unique = true)
      @Pattern(regexp = &quot;[A-Za-z0-9_.-]+&quot;, message = &quot;Solo se permite:'_' o '.' o '-'&quot;)
      private String username;
  
      @NotBlank(message = &quot;Password cannot be null&quot;)
      @Pattern(regexp = &quot;[^ ]*+&quot;, message = &quot;Caracter: ' ' (Espacio en blanco) invalido&quot;)
      @Size(min = 6, max = 20, message = &quot;About Me must be between 6 and 20 characters&quot;)
      private String password;
  
      @NotBlank(message = &quot;Cell phone cannot be null&quot;)
      @Pattern(regexp = &quot;[0-9]+&quot;, message = &quot;Solo numeros&quot;)
      @Size(max = 50)
      @Indexed(unique = true)
      private String cellPhone;
  
      @NotBlank(message = &quot;Email cannot be null&quot;)
      @Size(max = 50)
      @Pattern(regexp = &quot;[^ ]*+&quot;, message = &quot;Caracter: ' ' (Espacio en blanco) invalido&quot;)
      @Email(message = &quot;Email should be valid&quot;)
      @Indexed(unique = true)
      private String email;
  
      private String codigo;
      private List&lt;String&gt; roles;
  
      ** Constructors, setters and getters
  }
  </code></pre>
  <p>My Client:</p>
  <pre><code>@FeignClient(name = &quot;app-usuarios&quot;)
  public interface UsersFeignClient {
  
      @GetMapping(&quot;/users/usuarioExisteDatos&quot;)
      public Boolean preguntarUsuarioExiste(@RequestParam(value = &quot;username&quot;) String username,
              @RequestParam(value = &quot;email&quot;) String email, @RequestParam(value = &quot;cellPhone&quot;) String cellPhone);
      
      @GetMapping(&quot;/users/listar&quot;)
      public List&lt;Usuario&gt; listarUsuarios();
  }
  </code></pre>
  <p>My controller:</p>
  <pre><code>@RestController
  public class RegistroController {
  
      private final Logger logger = LoggerFactory.getLogger(RegistroController.class);
  
      @SuppressWarnings(&quot;rawtypes&quot;)
      @Autowired
      private CircuitBreakerFactory cbFactory;
  
      @Autowired
      UsersFeignClient uClient;
  
      @GetMapping(&quot;/registro/listarUsuarios&quot;)
      public List&lt;Usuario&gt; verUsuarios() {
          return uClient.listarUsuarios();
      }
  
      @PostMapping(&quot;/registro/crearNuevo&quot;)
      @ResponseStatus(code = HttpStatus.CREATED)
      public Boolean crearNuevo(@RequestBody @Validated Registro registro) {
          // return uClient.preguntarUsuarioExiste(registro.getUsername(),
          // registro.getEmail(), registro.getCellPhone());
          return (Boolean) cbFactory.create(&quot;usuarios&quot;).run(() -&gt; uClient.preguntarUsuarioExiste(registro.getUsername(),
                  registro.getEmail(), registro.getCellPhone()), e -&gt; preguntarUsuarioExiste2(registro.getUsername(), e));
      }
  
      private Object preguntarUsuarioExiste2(String username, Throwable e) {
          logger.info(e.getMessage());
          return false;
      }
  
  }
  </code></pre>
  <p>my application properties:</p>
  <pre><code>#-------APP-------
  spring.application.name=app-registro
  server.port=${PORT:0}
  
  #-----MongoDb------
  spring.data.mongodb.host=localhost
  spring.data.mongodb.port=27017
  spring.data.mongodb.authentication-database=admin
  spring.data.mongodb.username=user
  spring.data.mongodb.password=user
  spring.data.mongodb.database=usuariosApp
  spring.data.mongodb.auto-index-creation: true
  
  #-----Eureka-------
  eureka.instance.metadataMap.instanceId=${spring.application.name}:${spring.application.instance_id:${random.value}}
  eureka.client.service-url.defaultZone=http://localhost:8761/eureka
  
  management.endpoints.web.exposure.include=*
  management.endpoint.health.show-details=always
  
  #-----Feign-------
  feign.client.config.default.connect-timeout=10000
  feign.client.config.default.read-timeout=10000
  feign.client.config.default.logger-level=full
  </code></pre>
  <p>My Pom.xml:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
      xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.5.7&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
      &lt;groupId&gt;com.app.registro&lt;/groupId&gt;
      &lt;artifactId&gt;App-Registro&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;App-Registro&lt;/name&gt;
      &lt;description&gt;Registro for App&lt;/description&gt;
      &lt;properties&gt;
          &lt;java.version&gt;11&lt;/java.version&gt;
          &lt;spring-cloud.version&gt;2020.0.4&lt;/spring-cloud.version&gt;
      &lt;/properties&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-mongodb&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-validation&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
              &lt;artifactId&gt;spring-cloud-starter-netflix-eureka-client&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
              &lt;artifactId&gt;spring-cloud-starter-openfeign&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
              &lt;optional&gt;true&lt;/optional&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
              &lt;artifactId&gt;lombok&lt;/artifactId&gt;
              &lt;optional&gt;true&lt;/optional&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-rest&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.springfox&lt;/groupId&gt;
              &lt;artifactId&gt;springfox-boot-starter&lt;/artifactId&gt;
              &lt;version&gt;3.0.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
              &lt;artifactId&gt;spring-cloud-starter-circuitbreaker-resilience4j&lt;/artifactId&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
      &lt;dependencyManagement&gt;
          &lt;dependencies&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-cloud-dependencies&lt;/artifactId&gt;
                  &lt;version&gt;${spring-cloud.version}&lt;/version&gt;
                  &lt;type&gt;pom&lt;/type&gt;
                  &lt;scope&gt;import&lt;/scope&gt;
              &lt;/dependency&gt;
          &lt;/dependencies&gt;
      &lt;/dependencyManagement&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
                  &lt;configuration&gt;
                      &lt;excludes&gt;
                          &lt;exclude&gt;
                              &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
                              &lt;artifactId&gt;lombok&lt;/artifactId&gt;
                          &lt;/exclude&gt;
                      &lt;/excludes&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>
  <p>My method in microservice usuarios:</p>
  <pre><code>@GetMapping(&quot;/users/usuarioExisteDatos&quot;)
      @ResponseStatus(HttpStatus.FOUND)
      public Boolean preguntarUsuarioExiste(@RequestParam(value = &quot;username&quot;) String username,
              @RequestParam(value = &quot;email&quot;) String email, @RequestParam(value = &quot;cellPhone&quot;) String cellPhone)
              throws InterruptedException {
          return uRepository.existsByUsernameOrEmailOrCellPhone(username, email, cellPhone);
      }
  </code></pre>
  <p>It should be noted that you are making a call to a MongoRepository interface</p>
  <p>If I call the other client method, listUsers, the feign client works fine:</p>
  <p><a href="https://i.stack.imgur.com/GI9QN.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GI9QN.jpg" alt="Users List" /></a></p>
  <p>My method in microservicie usuarios for this is:</p>
  <pre><code>@GetMapping(&quot;/users/listar&quot;)
      @ResponseStatus(code = HttpStatus.CREATED)
      public List&lt;Usuario&gt; listarUsuarios() {
          return uRepository.findAll();
      }
  </code></pre>
  <p>I don't understand why this happens</p>