【问题标题】:HelloRestAPI showing 404 (created with IntelliJ Spring Initializr)HelloRestAPI 显示 404(使用 IntelliJ Spring Initializr 创建)
【发布时间】:2023-01-27 20:04:06
【问题描述】:

我对那个初学者问题感到非常沮丧 只需使用 JDK 18 和 UpToDate IntelliJ 启动一个全新的 Spring Boot 项目。

不再插入此控制器的代码:

package com.example.springboot;

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

@RestController
public class HelloController {

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

}

打电话:卷曲本地主机:8080并得到一个不寻常的 404:

The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

搜索该响应将我指向谈论视图 jsp 和 web.xml 的非常古老的线程

但我不想有令人讨厌的效果图。我想要纯 REST-Controller。

有什么建议可以指出正确的问题或者更好的解决方案吗?

【问题讨论】:

    标签: spring spring-boot spring-restcontroller


    【解决方案1】:

    pom.xml 中需要 spring-boot-starter-web 依赖项

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

    当您使用 IntelliJ 创建新项目时,它会询问您要包含的依赖项。这里需要选择“Spring Web”:

    【讨论】:

      猜你喜欢
      • 2015-12-05
      • 2019-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-13
      相关资源
      最近更新 更多