Error creating bean with name 'requestMappingHandlerMapping' Spring Boot

In all your request mappings, you have incorrectly used name instead of value

@RequestMapping(name = "/servers/{id}", method = RequestMethod.GET)

should be

@RequestMapping(value = "/servers/{id}", method = RequestMethod.GET)

As a result of this, both getServer and newServer were trying to map to the same URL - GET / which is not allowed.


Generally, this error comes when you put the same URL mapping with in the same controller or any other controller class for the same method Types. For example -

@GetMapping(value = "/asset", produces = { MediaTypes.APPLICATION_JSON_UTF8 })
ResponseEntity<ApiResponse<Object>> getAssetData(String assetId) {}

@GetMapping(value = "/asset", produces = { MediaTypes.APPLICATION_JSON_UTF8 })
ResponseEntity<ApiResponse<Object>> getAllAssets() {}

In this case, we are using the same method type with the same URL mappings which are wrong. This mapping should be unique within all controllers for the same method types.

You can use the same mapping only for HTTP method types like GET, POST, PUT, DELETE but only once.

But

if Accept Header value (produces) is different for the same mapping than there is no problem for same method also.

@GetMapping(value = "/asset", produces = { MediaType.APPLICATION_JSON_VALUE })
    ResponseEntity<ApiResponse<Object>> getAssetData(String assetId) {}

@GetMapping(value = "/asset", produces = { MediaType.APPLICATION_XML_VALUE })
    ResponseEntity<ApiResponse<Object>> getAssetData(String assetId) {}

It will work fine because "produces" value is different for even the same URL mapping.