Java – Spring Boot – Request method ‘POST’ not supported endless warning

java, spring, spring-boot, spring-mvc

I looked at the other posts on SO and have not found the answer.

I created a Spring Boot application that currently only has 3 GET web services.
I do not have any POST methods.

When I run the application, the console warning keeps looping over and over.

o.s.web.servlet.PageNotFound : Request method 'POST' not

Is this something I need to be concerned about? Or is it only showing because I did not implement any POST services?

Project Structure –
Controller -> Manager/ManagerImpl -> DAO/DAOImpl.

When I make a call to the webservice, it is simply reading from a Oracle DB using JDBC and spitting them back out in JSON.

Controller Code –

@[email protected](value = "/forms")public class FormController {    @Autowired    private FormManager formManager;    @RequestMapping(value = "/{formId}", method = RequestMethod.GET)    public FormObj getFormForFormId(@PathVariable int formId) throws Exception {        FormObj forms = new FormObj();        try {            forms = formManager.getFormForFormId(formId);        } catch (Exception e){            throw new RemoteException("Error getting forms for formId- " + formId + " " + e.getMessage());        }        return forms;    }    @RequestMapping(method = RequestMethod.GET)    public List<FormObj> getFormsforUserId(@RequestParam(value="userId", defaultValue="0") int userId) throws Exception {        List<FormObj> forms = new ArrayList<>();        try {            forms = formManager.getFormForUserId(userId);        } catch (Exception e){            throw new RemoteException("Error getting forms for UserId- " + userId + " " + e.getMessage());        }        return forms;    }    @RequestMapping(value = "/time", method = RequestMethod.GET)    public long greeting(@RequestParam(value="name", defaultValue="World") String name) {        return Calendar.getInstance().getTimeInMillis();    }}

Best Solution

As asked by the OP, I am posting my answer.

@RequestParam works with both GET and POST methods. You can also find more information on this SO post.

Like @zeroflagL commented, someone is making a POST request. My best bet is the that the @RequestParamis at fault, which is true, as you say. Now, I cannot tell you exactly why or what is happening in there since I do not have your entire codebase to look into (Spring has a lot of moving parts as we know). Maybe there is some client-end code that is sending a POST request to the backend without your knowledge. I am more focused on the client-end since, the problem you are facing is that an unknown POST request is being made to the backend, which Spring cannot map to any methods, and this can only be done from the client side.

The next steps that you could do:

  1. Remove the @RequestParam usages one at a time and see which one creates the problem. Like you said, when you did remove the @RequestParam from the greeting() method, the error was gone. Maybe that is the problem. Yet try with the other methods too, in this case, getFormsForUserId() method.
  2. Once you do have the method that creates the problem, check the corresponding client end code for that request and see if you find any anomaly there. Maybe the problem is there after all!

Hope this helps. :)

P.S. if you find the reason behind the problem, do let me know. Feels good to learn new stuff.