1

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); } } } 
2
  • Post the error message you get the console. Also let me know the URL of the HTTP request that you are trying to request. Commented Feb 23, 2015 at 6:34
  • The error is "Request method 'POST' not supported" and the URL is "localhost:8080/setMessages" Commented Feb 23, 2015 at 15:09

2 Answers 2

2

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)

Sign up to request clarification or add additional context in comments.

Comments

-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

1 Comment

Can you post the relevant parts of the 24 minute video in text?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.