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

238
Visualizações
Spring Exception: MethodArgumentTypeMismatchException

I'm getting and exception that I do not understand. I have a controller, it gives me back a news object and it appears in the Console, so getting the actual news object is not the problem,

@RequestMapping(value ="/viewonestatus/{id}")
public ModelAndView viewOneStatus(@PathVariable("id") Long id) {

    System.out.println("!!!!!! STATUSUPDATECONTROLLER: viewOneStatus : Empezamos con el ID del Anuncio: " + id);

    StatusUpdate status = statusUpdateService.get(id);

    ModelAndView modelAndView = new ModelAndView();
    System.out.println("!!!!!! STATUSUPDATECONTROLLER: viewOneStatus : Empezamos con el ID del Anuncio: " + status);

    modelAndView.getModel().put("status", status);

    modelAndView.setViewName("viewonestatus");

    return modelAndView;
}

.... but when try to execute the JSP it gives me the following error, even with an almost empty JSP, like....

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%> 
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>

hello world

Exception: Exception: org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type [java.lang.String] to required type [java.lang.Long]; nested exception is java.lang.NumberFormatException: For input string: &#034;viewonestatus&#034;
        Failed URL: http://localhost:8080/viewonestatus/viewonestatus
        Exception message: Failed to convert value of type [java.lang.String] to required type [java.lang.Long]; nested exception is java.lang.NumberFormatException: For input string: &#034;viewonestatus&#034;

Thanks a lot for your help

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

@RequestMapping(value ="/viewonestatus/{id}")
public ModelAndView viewOneStatus(@PathVariable("id") Long id)

Here you are declaring a path variable named "id" and you declare its type as Long. Nextly you are calling url:

http://localhost:8080/viewonestatus/viewonestatus 

the second "viewonestatus" is obviously not a Long type and this is why spring is throwing an exception because it can't convert "viewonestatus" to Long

your reqeust should look like

http://localhost:8080/viewonestatus/12321
about 4 years ago · Santiago Trujillo Relatório

0

Well, this was driving me nuts for about 1/2 hour. If you're using SpringBoot, this could help you.

I realized in my controller I was using

@Controller

in stead of

@RestController

That was it. Ugh.

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