Java 尝试运行演示应用程序,但tomcat似乎正在运行,但浏览器抛出404

Java 尝试运行演示应用程序,但tomcat似乎正在运行,但浏览器抛出404,java,spring-boot,Java,Spring Boot,这是我的POM: https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 org.springframework.boot spring启动程序父级 2.2.0.M5 com.example 演示 0.0.1-快照 演示 SpringBoot的演示项目 <properties> <java.version>1.8</java.version> </properties> <depe

这是我的POM:

https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 org.springframework.boot spring启动程序父级 2.2.0.M5 com.example 演示 0.0.1-快照 演示 SpringBoot的演示项目

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
    </dependency>

    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-core</artifactId>
    </dependency>

    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-el</artifactId>
    </dependency>

    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-websocket</artifactId>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/milestone</url>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>`enter code here`spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/milestone</url>
    </pluginRepository>
</pluginRepositories>
这是我的控制器:

package com.example.demo;

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

@RestController
public class HelloController {

    @RequestMapping("/hello")
    public String index() {
        return "Greetings from Spring Boot!";
    }

}
输出显示一切都已启动并运行:

但浏览器给了我404-当我尝试这样做时找不到

不知道发生了什么事

Application.properties文件:

server.port=9080


您是否在该端口的属性文件中配置了它?我认为默认情况下,服务器启动于8080,而不是9080com.example.demo.DemoApplication:在笔记本电脑上启动DemoApplication-GQ31D0D4,PID 12544 com.example.demo.DemoApplication:未设置活动配置文件,返回默认配置文件:默认o.s.b.w.embedded.tomcat.TomcatWebServer:tomcat已使用端口9080(http)初始化……o.s.b.w.embedded.tomcat.TomcatWebServer:tomcat已在端口9080(http)上启动,上下文路径为“”com.example.demo.DemoApplication:在1.253秒内启动DemoApplication(JVM运行时间为1.577)我怀疑问题在于您没有为RequestMapping提供请求方法。请尝试提供它,或者改用GetMapping。您可以将
应用程序.properties
文件添加到问题吗?添加了application.properties文件
package com.example.demo;

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

@RestController
public class HelloController {

    @RequestMapping("/hello")
    public String index() {
        return "Greetings from Spring Boot!";
    }

}