【问题标题】:I am developing simple Rest service which will return simple "Hello", but i am unable to run that on tomcat server我正在开发简单的 Rest 服务,它将返回简单的“Hello”,但我无法在 tomcat 服务器上运行它
【发布时间】: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


【解决方案1】:

这就是我所做的,它与 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!!!";
    }
}

【讨论】:

    猜你喜欢
    • 2023-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多