我的控制器的SpringRESTURL是什么?

我的控制器的SpringRESTURL是什么?,spring,spring-restcontroller,spring-rest,Spring,Spring Restcontroller,Spring Rest,我从头开始构建rest应用程序,我只创建了基本的rest控制器,我想试试它是否有效 这是: @RestController @RequestMapping("/api") public class MyController { @GetMapping("/test") public String poll(@RequestParam Long messageId) { return "ok"; } } 我在浏览器中尝试了此url: 但我得到了错误40

我从头开始构建rest应用程序,我只创建了基本的rest控制器,我想试试它是否有效

这是:

@RestController
@RequestMapping("/api")
public class MyController {

    @GetMapping("/test")
    public String poll(@RequestParam Long messageId) {
        return "ok";
    }
}
我在浏览器中尝试了此url:

但我得到了错误404

此应用程序没有/error的显式映射,因此您可以看到 这是一种退路

2018年4月25日星期三21:23:35 CEST出现意外错误(类型=非 已找到,状态为404)。没有可用的消息

你能告诉我这个rest控制器的正确url是什么吗?谢谢

编辑1: 这是来自日志,因此端口也正常:

Tomcat started on port(s): 8080 (http) with context path ''
编辑2:

spring.datasource.url=jdbc:postgresql://localhost:5432/mydb
spring.datasource.username=xxx
spring.datasource.password=xxx
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create-drop

请尝试
公共字符串轮询(@RequestParam(“messageId”)Long messageId){

您可能在此处错过了项目名称:

http://localhost:8080/[PROJECT_NAME]/api/test?messageId=61

我在这里有可能的理论:

原因1:根据我的经验,我习惯于这样做:对于@GetMapping注释,我会键入

@GetMapping(“/test/{messageId}”)

然后我会将您的方法更改为:

public String poll(@PathVariable Long messageId){...}
原因2:我认为url应该是?61


我希望这会有所帮助,以防两种解决方案都不起作用,我鼓励您一起测试它们。

启动应用程序时,您还应该在日志文件中看到Spring检测到的所有URL映射。检查您的端点是否在那里。是的,它们将打印映射“{[/api/test],methods=[GET]}”您有哪个版本的Spring Boot?我已经在1.5.8上测试了您的代码,并且它运行了。@AdamLesiak感谢您的努力,我正在2.0.1中使用2.01Hm…还有工作事件副本粘贴您的代码:)。您可以从配置文件中放入代码吗?application.properites或application.yml。但是上下文路径是“”。虽然此代码可以回答这个问题,提供关于此代码为什么和/或如何回答此问题的附加上下文可提高其长期价值。