Kshitiz Sharma
Kshitiz Sharma

Reputation: 792

Request method 'DELETE' not supported

I started learning Spring boot and am trying to make a simple REST service for implementing CRUD operations on employee records. But I am getting this error while executing the DELETE method-

{ "timestamp": "2018-08-10T11:17:47.619+0000", "status": 405, "error": "Method Not Allowed", "message": "Request method 'DELETE' not supported", "path": "/employees/123" }

My Controller-

@DeleteMapping("/employee/{id}")
public String deleteEmployee(@PathVariable int id) {
    return employeeService.deleteEmployee(id);

}

My Service-

public String deleteEmployee(int id) {
    // TODO Auto-generated method stub
    for(int i=0;i<list.size();i++) {
        if(list.get(i).getId()==id) {
            list.remove(i);
        }
    }
    return "Employee withh id "+id+" has been removed from the company";
}

Upvotes: 2

Views: 15639

Answers (1)

cringe
cringe

Reputation: 13950

In the output you pasted the path is /employees/123 which does not match your @DeleteMapping("/employee/{id}").

Upvotes: 16

Related Questions