【发布时间】:2016-12-20 20:18:14
【问题描述】:
当我在 Spring Boot 中启动我的迷你项目(主要是我从 start.spring.io 生成)时,从命令行通过命令 mvn spring-boot:run 并步行到 http://localhost:8080/test/{michal} 我看到 404 失败。
除此之外,我无法使用 Response.create 在控制器类中创建返回语句 -> 它显示:
未为类型 Response 定义方法 create(String)
我认为这是我的应用程序不想正常运行的主要问题。
这是我的控制器类
@RestController
public class TestController {
@Autowired
private TestService testService;
@RequestMapping(value = "/test/{name}", method = RequestMethod.GET)
public Response<String> /*@ResponseBody String*/ getWelcomeText(@PathVariable("name") String name) {
return Response.create(testService.loadWelcomeText(name));
}
}
这是我的服务类
@Service
public class TestService {
public String loadWelcomeText(String name) {
return "Hello " + name;
}
}
我有@ComponentScan 注释
【问题讨论】:
-
最好修改您的原始帖子,而不是添加带有详细信息的答案。你能删除你的“答案”并更新帖子吗?此外,您使用的 URL 有点奇怪
http://localhost:8080/test/{michal}。为什么它有花括号?你真的需要它们吗?
标签: spring-mvc spring-boot http-status-code-404