springmvc Posts

How to Find Root Cause of Error 400 on SpringMVC using Log4J

Error 400 is basically telling us that our request is syntactically incorrect. But it will need a while to found out which parameter is incorrect, especially when you are submitting a lot of parameters.

But do not worry, on SpringMVC we can always log which parameters causing error 400 using Log4J. Adding these values on your log4j.properties will display the error location.

log4j.logger.org.springframework.web=debug

And we can see the root cause on our log file,

2017-02-28 22:33:07,241 [DefaultHandlerExceptionResolver] DEBUG org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver:133 - Resolving exception from handler [public java.util.Map xxx.yyy.controller.ZZZController.saveZZZ(xxx.yyy.bean.DDDD,org.springframework.web.multipart.MultipartFile,org.springframework.web.multipart.MultipartFile,javax.servlet.http.HttpSession)]: org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'DDDD' on field 'rupiah': rejected value [100.000.000,000000]; codes [typeMismatch.DDDD.rupiah,typeMismatch.rupiah,typeMismatch.java.math.BigDecimal,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [DDDD.rupiah,rupiah]; arguments []; default message [rupiah]]; default message [Failed to convert property value of type 1 to required type 1 for property 'rupiah'; nested exception is java.lang.NumberFormatException]

As you can see, it happens because i expect a BigDecimal on my bean, but i send a String instead.

Google+