'Java spring POST request status 404
I'm following a tutorial and my POST request is getting a 404 response. I dont understand why.
I have rewatched the tutorial many times and compared with another project and still can't find the error.
I appreciate all the help possible
PersonController:
import model.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import service.PersonService;
@RestController
@RequestMapping(path = "api/v1/person")
public class PersonController {
private final PersonService personService;
@Autowired
public PersonController(PersonService personService) {
this.personService = personService;
}
@PostMapping
public void addPerson(@RequestBody Person person){
personService.addPerson(person);
}
}
Service:
import dao.PersonDao;
import model.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
@Service
public class PersonService {
private final PersonDao personDao;
@Autowired
public PersonService(@Qualifier("fakeDao") PersonDao personDao) {
this.personDao = personDao;
}
public int addPerson(Person person){
return personDao.insertPerson(person);
}
}
A part of run:
2022-05-17 16:02:34.886 TRACE 120467 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping :
o.s.b.a.w.s.e.BasicErrorController:
{ [/error]}: error(HttpServletRequest)
{ [/error], produces [text/html]}: errorHtml(HttpServletRequest,HttpServletResponse)
2022-05-17 16:02:34.889 DEBUG 120467 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : 2 mappings in 'requestMappingHandlerMapping'
Postman:
{
"timestamp": "2022-05-17T15:02:39.240+00:00",
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/api/v1/person"
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
