Sobes.tech
Junior — Middle

Where in the Spring configuration is the HTTP method for handling requests defined?

sobes.tech AI

Answer from AI

In Spring, the HTTP method for handling requests is specified in controller annotations such as @GetMapping, @PostMapping, @PutMapping, @DeleteMapping, etc., or in a more general @RequestMapping annotation with the method parameter.

Example:

@RestController
public class MyController {
    @GetMapping("/items")
    public List<Item> getItems() {
        return ...;
    }

    @RequestMapping(value = "/items", method = RequestMethod.POST)
    public Item createItem(@RequestBody Item item) {
        return ...;
    }
}

Thus, the HTTP method is set directly in the controller configuration via annotations, rather than in separate configuration files.