I'm trying to make 2 microservices communicate with Open Feign. The two microservices are student and address. When I'm trying to call the method written in feign client I'm getting this exception

feign.FeignException: [302] during [GET] to [http://ADDRESS-SERVICE/address/student/1] [AddressClient#getParticularStudentAddressById(Long)]: [{"addressId":1,"city":"Greater Noida","country":"India","studentId":1}]

I'm getting the JSON response I'm expecting in error message but not as a POJO object.

This is my Feign Client in student microservice

@FeignClient(value = "ADDRESS-SERVICE", path = "/address")
public interface AddressClient {

    @GetMapping("/student/{studentId}")
    public ResponseEntity<Address> getParticularStudentAddressById(@PathVariable Long studentId);
}

This is address controller method

@GetMapping("/student/{studentId}")
    public ResponseEntity<Address> getParticularStudentAddressById(@PathVariable Long studentId) {
        Address response = addressService.getAddressOfStudent(studentId);
        return new ResponseEntity<Address>(response, HttpStatus.FOUND);
}

Does anyone have any idea what I might be missing and what is leading to this exception?

Comment From: kbaluc

Try changing HttpStatus.FOUND to some 2XX code like HttpStatus.OK

Comment From: gerson-eduardo

Try changing HttpStatus.FOUND to some 2XX code like HttpStatus.OK

Thanks for the help. You saved me.

Comment From: OlgaMaciaszek

@Akshu01, you are getting 302 because that's what you're returning in controller method (HttpStatus.FOUND). You can read more here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302.

Comment From: iamkrishna73

You’re my saviour.

Comment From: Pradwin

Thanks for the help