This little program
@SpringBootApplication
@RestController
public class HelloworldApplication {
public static void main(String[] args) {
SpringApplication.run(HelloworldApplication.class, args);
}
@GetMapping(path = "")
public ResponseEntity<String> sayHello() {
return new ResponseEntity<>("Hello world!", HttpStatus.OK);
}
}
gives the expected output on GET localhost:8080 with Spring Boot 2.7.9-SNAPSHOT.
On Spring Boot 3.0.3-SNAPSHOT it only gives a 404 error though. Can anybody tell me how to fix it?
build.gradle:
plugins {
id 'java'
id 'org.springframework.boot' version '3.0.3-SNAPSHOT'
id 'io.spring.dependency-management' version '1.1.0'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '19'
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
}
I also tried Spring Boot 3.0.0 and 3.0.2. When I enter "localhost:8080" in the Browser address line, I expect to see "Hello world". Instead, I get a 404 white-label page
CodePudding user response:
The path segment must not be empty.
This will fix your problem:
@GetMapping(path = "/")