404在正确映射的SpringBoot RestController上

404在正确映射的SpringBoot RestController上,spring,rest,spring-boot,controller,Spring,Rest,Spring Boot,Controller,我遇到了一个小问题,浪费了我很多时间 为了演示,我使用EclipseNew>SpringStarter项目创建了一个简单的SpringBoot应用程序 这是我的应用程序类: package it.asirchia; //All needed imports @SpringBootApplication public class Application { public static HashMap<Long,Book> books = new HashMap<Lo

我遇到了一个小问题,浪费了我很多时间

为了演示,我使用EclipseNew>SpringStarter项目创建了一个简单的SpringBoot应用程序

这是我的应用程序类:

package it.asirchia;

//All needed imports

@SpringBootApplication
public class Application {

    public static HashMap<Long,Book> books = new HashMap<Long, Book>();
    public static HashMap<Long,Editor> editors = new HashMap<Long, Editor>();
    public static HashMap<Long,Person> authors = new HashMap<Long, Person>();

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
我获得:

{
"timestamp": 1507286437765,
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/authors"
}
对于我实现的所有RESTAPI,也是如此。 你知道这个问题的原因吗?
谢谢。

您可以尝试在value中添加一个动作内容。这里只指定一个“/”.Like

如果您需要添加任何path变量,您可以使用以下命令对其进行修改:

@RequestMapping(value="/updateEditor/{editorid}", method=RequestMethod.PUT)

也可以尝试此方法。

以下映射将对您有效。localhost:8080/authors/。由于在方法映射GET中添加了“/”,因此您还应该在URL中提供尾部斜杠。如果您希望像这样映射,请遵循以下代码:

@RequestMapping(value={"","/"}, method=RequestMethod.GET)
public HashMap<Long, Editor> getAllEditor(){
    return Application.editors;
}
@RequestMapping(值={“”“/”},方法=RequestMethod.GET)
公共HashMap getAllEditor(){
返回应用程序编辑器;
}
上述条款将被接受

1) localhost:8080/editors

2) localhost:8080/editors/


希望这会有所帮助。

试试localhost:8080/editors/或localhost:8080/authors/。我试过了,它应该有用。。。它在@VelNaga中不起作用,它的尾部斜杠起作用了。。。谢谢你能添加你的application.properties吗?@Cyril my application.properties为空。
 @RequestMapping(value="/updateEditor", method=RequestMethod.GET)
@RequestMapping(value="/updateEditor/{editorid}", method=RequestMethod.PUT)
@RequestMapping(value={"","/"}, method=RequestMethod.GET)
public HashMap<Long, Editor> getAllEditor(){
    return Application.editors;
}