简体   繁体   中英

HelloRestAPI showing 404 (created with IntelliJ Spring Initializr)

I am totally frustrated about that beginnerproblem Simply startet a fresh SpringBoot Project with JDK18 and UpToDate IntelliJ.

Inserted no more Code that this 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!";
    }

}

calling: curl localhost:8080 and get an unusual 404:

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

Searching for that response pointing me to very old threads talking about views jsp and web.xml

But I dont want to have nasty renderings. I want pure REST-Controller.

Any suggestion to point me to the correct issue or even better to a solution?

The spring-boot-starter-web dependency is required in your pom.xml

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

When you create a new project with IntelliJ it asks for the dependencies you want to include. Here you need to select "Spring Web":

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM