【发布时间】:2019-05-26 01:23:06
【问题描述】:
我使用 Spring Boot Initial 创建了 Spring Boot 项目,然后在运行时解压缩了在 Eclipse 中导入的项目。它运行良好。 但是在开发简单的hello rest服务时。找不到 404
尝试删除tomcat服务器并重新配置 服务器在同一台服务器上运行良好。
这是我的 Rest Controller 类
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
//Controller
@RestController
public class HelloWorldController {
//Method- HelloRest!!
//URI- /hello-rest
//GET- request
//@RequestMapping(method=RequestMethod.GET,path="/hello-rest")
@GetMapping(path = "/hello-world")
public String helloWorld() {
return "Hello World!!";
}
}
【问题讨论】:
-
请分享您的错误,代码可以帮助我们识别您的问题。欢迎来到社区。span>
-
缺少您的 Rest Controller 类
-
这是我的restContoller类-import org.springframework.web.bind.annotation.GetMapping;导入 org.springframework.web.bind.annotation.RequestMapping;导入 org.springframework.web.bind.annotation.RequestMethod;导入 org.springframework.web.bind.annotation.RestController; //Controller @RestController public class HelloWorldController { //Method- HelloRest!! //URI- /hello-rest //GET- 请求 //@RequestMapping(method=RequestMethod.GET,path="/hello-rest") @GetMapping(path = "/hello-world") public String helloWorld() {返回“你好世界!!”; } }
-
请确保您的 hello-world 控制器应位于相同的包级别或启动器/主类的子包级别(即@SpringBootApplication)
标签: java eclipse rest maven spring-boot