簡體   English   中英

HelloRestAPI 顯示 404(使用 IntelliJ Spring Initializr 創建)

[英]HelloRestAPI showing 404 (created with IntelliJ Spring Initializr)

我對那個初學者問題感到非常沮喪只需使用 JDK18 和 UpToDate IntelliJ 啟動一個新的 SpringBoot 項目。

不再插入此 Controller 的代碼:

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!";
    }

}

調用: curl localhost: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。

有什么建議可以指出正確的問題或者更好的解決方案嗎?

您的 pom.xml 中需要 spring-boot-starter-web 依賴項

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

當您使用 IntelliJ 創建新項目時,它會詢問您要包含的依賴項。 這里需要select《Spring Web》:

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM