首页 > 解决方案 > 我正在开发简单的 Rest 服务,它将返回简单的“Hello”,但我无法在 tomcat 服务器上运行它

问题描述

我使用 spring boot initial 创建了 Spring boot 项目,然后在运行时解压缩了在 eclipse 中导入的项目。它运行良好。但是在开发简单的hello rest服务时。找不到 404

尝试删除tomcat服务器并再次配置它服务器在同一台服务器上运行良好。

这是我的休息控制器类

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!!"; 
  } 
}

标签: javaeclipserestmavenspring-boot

解决方案


这就是我所做的,它与 tomcat 和 JBoss 一起工作。 http://localhost:8085/test/testCall - 这是我在邮递员中为以下代码点击的 URL。你能分享你想点击的网址吗

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class ServiceController {
    @RequestMapping(value="/testCall", method=RequestMethod.GET)
    public String  testCall(){
        return "Service Up!!!";
    }
}

推荐阅读