Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

2.4K
Vistas
Bug: Required request body is missing

I'm trying spring framework. I have RestController and function:

@RequestMapping(value="/changePass", method=RequestMethod.POST)
    public Message changePassword(@RequestBody String id, @RequestBody String oldPass, 
                                                        @RequestBody String newPass){
        int index = Integer.parseInt(id);
        System.out.println(id+" "+oldPass+" "+newPass);
        return userService.changePassword(index, oldPass, newPass);
    }

and code angularJS

$scope.changePass = function(){//changePass
        $scope.data = {
            id: $scope.userId,
            oldPass:$scope.currentPassword,
            newPass:$scope.newPassword
        }
        $http.post("http://localhost:8080/user/changePass/", $scope.data).
            success(function(data, status, headers, config){
                if(date.state){
                    $scope.msg="Change password seccussful!";
                } else {
                    $scope.msg=date.msg;
                }
        })
        .error(function(data, status, headers, config){
            $scope.msg="TOO FAIL";
        });
    }

and when i run it.

Error Message :

Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public com.csc.mfs.messages.Message com.csc.mfs.controller.UserController.changePassword(java.lang.String,java.lang.String,java.lang.String)

Help me fix it, pls...

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Issue is in this code.

@RequestBody String id, @RequestBody String oldPass, 
                                                        @RequestBody String newPass

You cannot have multiple @RequestBody in same method,as it can bind to a single object only (the body can be consumed only once).

APPROACH 1:

Remedy to that issue create one object that will capture all the relevant data, and than create the objects you have in the arguments.

One way for you is to have them all embedded in a single JSON as below

{id:"123", oldPass:"abc", newPass:"xyz"}

And have your controller as single parameter as below

 public Message changePassword(@RequestBody String jsonStr){

        JSONObject jObject = new JSONObject(jsonStr);
.......
 }

APPROACH 2:

Create a custom implementation of your own for ArgumentResolver

about 4 years ago · Santiago Trujillo Denunciar

0

You can't have request body for the GET method. If you want to pass username and password as part of request body then change RequestMethod type to POST/PUT.

If you want to use GET only then you will have to pass username and password as either path variables or request/query parameters - which is not best practice.

I would recommend changing RequestMethod and pass username & password as request body.

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda