【发布时间】:2020-08-15 06:16:42
【问题描述】:
我创建了简单的 Spring Boot 应用程序。我尝试了很多次,但每次在 Pivotal tc 服务器上运行它时都会抛出错误:404 错误。如果有人能帮助我,那就太好了。我已经使用 Spring Boot Starter Class 创建了 Controller 类。在我收到的错误的图像下方。Pivotal Server 已启动并在端口 8082 上运行,但只要我输入 /hello 到 localhost:8082,我就会收到错误 404(我有最后也共享了 Pivotal 服务器的图像)。我几乎尝试了 google 上可用的所有内容。我是 Spring Boot 的初学者,如果有人能提出解决这个问题的建议,我将不胜感激。我还共享了 pom.xml。
404 错误截图-->Error Image.
我正在使用 url:http://localhost:8082/hello 的关键 tc 服务器上运行它
链接到 Pivotal 服务器 url 截图--->Pivotal server with controller return url Image Pivotal 服务器已启动并正在运行,但只要我输入 http://localhost:8082/hello, 我收到 404 错误。任何人都可以帮忙。我已经尝试了所有可以搜索的内容。
链接到 Pivotal 服务器启动并运行屏幕截图-->Pivotal server up and running image
Spring Boot Starter 类的代码:
package io.javabrains.springbootstarter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class CourseApiApp {
public static void main(String[] args) {
SpringApplication.run(CourseApiApp.class,args);
}
}
控制器类代码:
package io.javabrains.springbootstarter.hello;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@RequestMapping("/hello")
public String sayHi()
{
return("Hello");
}
}
Pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-
4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.javacheck.springbootquickstart</groupId>
<artifactId>course-api-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Java Brains Course Api</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<!-- WEB -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
</project>
【问题讨论】:
-
您确定服务器在 8082 端口上运行吗?
-
是的,它在 8082 运行。当我输入 /hello 到 localhost:8082 时,我收到错误 404。我还按名称共享了图像-->“Pivotal 服务器启动并运行图像”。
-
你检查控制台输出了吗?
-
你有在localhost:8082/manager 中运行的Tomcat 管理器吗?您是否能够查看您的应用程序是否已部署?您会在服务器启动日志中看到类似的消息,说明应用是否已部署。
标签: java azure spring-boot azure-api-apps