我已经创建了演示 Spring Boot 项目并实现了 Restful 服务,如此处所示
@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);
}
}
当我尝试使用 Postman 工具以 url“ http://localhost:8080/api/greetings ”作为请求方法 GET 调用服务时,出现以下错误消息
{
"timestamp": 1449495844177,
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/api/greetings"
}
对于 Spring Boot 应用程序,我不必在 web.xml 中配置 Spring Dispatcher servlet。
有人可以帮我找出这里的遗漏点吗?
原文由 Naveen 发布,翻译遵循 CC BY-SA 4.0 许可协议
你可能错过了
@SpringBootApplication
:@SpringBootApplication
包括@ComponentScan
扫描它所在的包和所有子包。您的控制器可能不在其中任何一个中。