Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

2.4K
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda