Search code examples
javaspringspring-restcontroller

Spring @RequestMapping absolute path


I've a RestController for a CRUD annotated like this:

@RestController
@RequestMapping("/rest/v1/area")
public class AreaController

My methods are annotated like:

@RequestMapping(value = "/{uuid}", method = RequestMethod.PUT)
public ResponseEntity<Area> save(@Valid @RequestBody Area area) {

Is there a way to use a value for a method to have an absolute path? I want to add a method to upload files, and don't want to make a new Controller just for this. I want a method like:

@RequestMapping(value = "/rest/v1/area-upload", method = RequestMethod.PUT
public String handleFileUpload(@RequestParam("file") MultipartFile file, RedirectAttributes redirectAttributes) {

Thanks!


Solution

  • From the documentation: (spring 2.5 api document of requestmapping)

    Method-level mappings are only allowed to narrow the mapping expressed at the class level (if any)

    So you cannot override, only narrow it down to sub-paths.

    Ofcourse if you create a new controller class and put the method there, you can have it point to whatever path you like.