Reputation: 21
Hi i have problem with my app. I am using Spring Boot/Rest and when i trying execute request HTTP i get error in console. Request method 'POST' not supported. GET working fine but POST not... and i don't know what i can do more This is my controller code.
@Controller
@RestController
public class MessageController {
@RequestMapping("/getMessages")
public List<Messages> getMessages(@RequestParam(value="id", defaultValue="1")int id){
DB db = new DB();
List<Messages> messages;
try {
messages = db.getMessages(id);
System.out.println("Pobieram wiadomosci: "+messages.size());
} catch (SQLException e) {
messages = null;
}
return messages;
}
@RequestMapping(value = "/setMessage", method = RequestMethod.POST)
public void checkUser(@RequestBody @Valid final Messages message) {
DB db = new DB();
try {
System.out.println("Message:"+message.getText()+" idUser:"+message.getUser());
db.setMessage(message.getRoom(), message.getText(), message.getUser().getId());
System.out.println("Wysyłam wiadomosc");
} catch (SQLException e) {
System.out.println("Error: " + e);
}
}
}
Upvotes: 1
Views: 7610
Reputation: 1
The URL is not correct mapping is wrong, use http://localhost:8080/setMessage in the client For more details watch: https://www.youtube.com/watch?v=7j6mLXlJ2YI&list=PLeaW10A6uFKMOMcmGp35yLbduIyQEcBj4&index=6
Upvotes: -1
Reputation: 14855
http://localhost:8080/setMessages
is not mapped in the controller.
Change the URL to http://localhost:8080/setMessage
Or change the mapping as this:
@RequestMapping(value = "/setMessages", method = RequestMethod.POST)
Upvotes: 2