Hello All,

i have issue similar to #14984. The only change is instead of HttpMediaTypeNotSupportedException i am having HttpRequestMethodNotSupportedException. It doesn't seem to work when i add assignableTypes for my global exception handler class. Could you please help me on this.

@ControllerAdvice(assignableTypes = Test.class)
public class RestExceptionResolver  
{
    @ExceptionHandler({MethodArgumentTypeMismatchException.class})
    public ResponseEntity<String> handleTypeMismatchException(final MethodArgumentTypeMismatchException ex) 
    {
        return handleResponseEntity("error.rest.method.mismatch.type.argument", ex.getName(), HttpStatus.BAD_REQUEST);
    }

    @ExceptionHandler({HttpRequestMethodNotSupportedException.class})
    public ResponseEntity<String> handleMissingMethodException(final HttpRequestMethodNotSupportedException ex) 
    {
        return handleResponseEntity("error.rest.method.not.found", ex.getMessage(), HttpStatus.METHOD_NOT_ALLOWED);
    }
}

As mentioned it works for MethodArgumentTypeMismatchException exception but not for HttpRequestMethodNotSupportedException.

Comment From: wilkinsona

The problem in #14984 was caused by an incorrect assignableType. In your case, adding one may or may not have been the right thing to do. It's impossible to tell from what you have shared thus far. If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

Comment From: desai1990

Test class:

@RestController
@RequestMapping("/resources/")
public class Test  
{
    @RequestMapping(value = "getLineValue/{lineid}", method = RequestMethod.GET, consumes = 
            MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    public String getValue(@PathVariable("lineid") final String lineId,
            @RequestParam(required = false) final boolean liveLine) 
    {
        return "Inside controller";
    }
}

i am using postman to hit the controller by using the following urls 1. http://localhost:8080/resources/getLineValue/1?liveLine=true1 - When this URL is sent from postman, it hits the MethodArgumentTypeMismatchException in the RestExceptionResolver class as the liveLine value is not a boolean value

2.http://localhost:8080/resources/getLineValue/ and http://localhost:8080/resources/getLineValue/?liveLine=true This should hit the HttpRequestMethodNotSupportedException in the RestExceptionResolver class. This is not working when i add the assignableTypes in the class. Without the assignableTypes it works fine.

Hope this helps.

Comment From: wilkinsona

Thanks, @desai1990, but that's not quite what we're looking for as it leaves too many things unknown. For example, I can't see what version of Spring Boot you're using or what dependencies you application has. As I requested above, please provide a complete yet minimal sample. That should be a complete project, perhaps using an app generated from start.spring.io as a starting point, that we can run to reproduce the problem.

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.