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

236
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 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