简体   繁体   中英

Spring POST request results in 404

I have this simple code:

import com.example.civicsenseapp.Model.Segnalazione;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ControlApp
{
    @RequestMapping(method = RequestMethod.POST, value="/creaSegnalazione")
    public void segnalazione(@RequestBody Segnalazione segnalazione)
    {
        System.out.println(segnalazione.getCognome());
    }
}

I used Spring Initializr and Thymeleaf to create the project. I don't know why, but this exact code (running without errors) gives me a 404 error when I perform a POST request, but if I open another project created yesterday with the same code, it works perfectly.

What's going on here?

You must have added some security around it or mistyped the url. In case you would be calling GET instead of POST, you will get 405 and not 404. So, most probably, its the wrong url you are trying.

Do you have a base URI set in Spring? Rather than using the default URI "/", it may be set to use something like "/api/" before your path. You can easily check this in your Spring configuration/properties.

依存关系问题,还是谢谢你

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM