得到“无可用消息". Spring Boot + REST应用程序出错 [英] Getting "No message available" error with Spring Boot + REST application
问题描述
我创建了演示Spring Boot项目并实现了Restful服务,如下所示
I have created demo Spring Boot project and implemented Restful services as shown here
@RestController
public class GreetingsController {
@RequestMapping(value="/api/greetings", method=RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> getGreetings(){
return new ResponseEntity<String>("Hello World", HttpStatus.OK);
}
}
当我尝试使用URL为 http://localhost:8080/api/greetings的Postman工具调用该服务时"作为请求方法GET,我收到以下错误消息
When I tried to invoke the service with Postman tool with url "http://localhost:8080/api/greetings" as request method GET, I am getting below error message
{
"timestamp": 1449495844177,
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/api/greetings"
}
对于每个Spring Boot应用程序,我不必在web.xml中配置Spring Dispatcher servlet.
Per Spring Boot application, I don't have to configure the Spring Dispatcher servlet in web.xml.
有人可以帮我找出这里的缺失点吗?
Can someone help me to find out the missing point here?
推荐答案
您可能缺少@SpringBootApplication
:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
@SpringBootApplication
包括@ComponentScan
,该文件扫描其所在的程序包和所有子程序包.您的控制器可能不在其中任何一个中.
@SpringBootApplication
includes @ComponentScan
which scans the package it's in and all children packages. Your controller may not be in any of them.
这篇关于得到“无可用消息". Spring Boot + REST应用程序出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!