【发布时间】:2016-09-27 20:48:18
【问题描述】:
我创建了一个基本的 Spring Boot Web 应用程序
@SpringBootApplication
public class ScanApplication {
public static void main(String[] args) {
SpringApplication.run(ScanApplication.class, args);
}
}
@RequestMapping(value = "/rest")
@RestController
public class MemberController {
@GetMapping(value = "/users/{memberId}/scan")
public ResponseEntity<Void> getCardId(@PathVariable("memberId") Long memberId)
...
}
}
在浏览器中,如果我调用
http://localhost:8080/rest/users/1/scan
我收到这条消息
此应用程序没有显式映射 /error,因此您将其视为后备。
2016 年 9 月 27 日星期二 16:46:37 EDT 出现意外错误(类型=未找到,状态=404)。 没有可用的消息
不明白为什么我会收到此消息。
【问题讨论】:
-
ScanApplication和MemberController在哪些包中? -
注意:确保您的主类位于其他类之上的根包中。当您运行 Spring Boot 应用程序(即使用 @SpringBootApplication 注解的类)时,Spring 将仅扫描您的主类包下的类。另见:stackoverflow.com/a/39017839/6372139
-
ScanApplication 和 MemberController 的包是什么?
-
+ 确保您的 application.properties 中没有为 server.contextPath 定义值,这会将上下文根添加到您的预期 url。
标签: spring spring-boot spring-restcontroller