java - 我正在开发简单的 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!!";
}
}
解决方案
这就是我所做的,它与 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!!!";
}
}
推荐阅读
- ssh - 文件夹保护
- javascript - 将几个数据从 Mat Dialog Angular 4 传回给父级
- php - 死亡联系表白页
- api - AS400 - CPF4028 - Öffnen von Teildatei PCOUT in SEQONLY(*NO) geändert
- ios - 在 Swift 中推送和弹出后视图不显示
- flutter - Flutter - 如何将变量从一个飞镖类传递到另一个飞镖类
- angular - 打字稿(离子应用程序) - 基本身份验证不起作用
- javascript - 创建元素,然后插入 html 标签
- time - mariadb sec_to_time 只显示到 23:59:59
- php - 使用 phpmailer 收不到电子邮件