我必須開發具有如下休息終點簡單SpringBoot應用程序調用REST API,404錯誤當控制器在SpringBoot
@SpringBootApplication
@RestController
@RequestMapping(value = "/api")
public class Example {
@RequestMapping(value="/home", method = RequestMethod.GET)
HttpEntity<String> home() {
System.out.println("-----------myService invoke-----------");
return new ResponseEntity<String>(HttpStatus.OK);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Example.class, args);
}
}
以上工作正常,並在當調用其餘終點返回200如, http://localhost:8080/api/home
但現在我有其餘端點移動到如下不同的類,
@RestController
@RequestMapping(value = "/api")
public class MyController {
@RequestMapping(value="/home", method = RequestMethod.GET)
HttpEntity<String> home() {
System.out.println("-----------myService invoke-----------");
return new ResponseEntity<String>(HttpStatus.OK);
}
}
和示例CL屁股的樣子,
@SpringBootApplication
public class Example {
public static void main(String[] args) throws Exception {
SpringApplication.run(Example.class, args);
}
}
現在我調用了終點,我得到以下錯誤,
{
"timestamp": 1446375811463,
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/api/home"
}
缺少什麼我在這裏嗎?
是' MyController'與'Example'在同一個包或子包中? –