Home > Back-end >  Springboot/Java Getting whitelabel error in simple hello world program
Springboot/Java Getting whitelabel error in simple hello world program

Time:12-12

I am trying to teach myself to code and very new to programming. I am following a Spring Boot Tutorial from amigoscode on Youtube : (https://www.youtube.com/watch?v=9SGDpanrc8U&t=980s)

This is the code I have in IntelliJ:

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class DemoApplication {

   public static void main(String[] args) {
      SpringApplication.run(DemoApplication.class, args);
   }
   @GetMapping
   public String hello() {
      return "hello world";
   }

}

The code appears to compile and run and Tomcat starts on port: 8080 But when I go to localhost:8080 I get a Whitelabel Eror Page instead of 'Hello World'.

I tried it on both Windows and Linux(Ubuntu), and I tried it with the windows firewall and my router firewall disabled.

As I said I am very new to computers and am also having problems connecting mySQL workbench to mySql Databases though I can manipulate them through the command line. I thought perhaps these problems might be related since they both seem to require me to connect to localhost.

CodePudding user response:

Check you pom.xml

I Guess spring boot version is set 3.0.0.

Youtube Tutorial, Spring Boot Version is 2.4.1

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.4.1</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

Save, in IntelliJ, Select Project, Mouse Right button, popup menu Maven -> Reload Project, and wait a moment. Menu Build -> Build Project.

But if you change version to 2.4.1, set java version to 8

<properties>
    <!--<java.version>17</java.version>-->
    <java.version>8</java.version>
</properties>

Terminal Build and Run

  • In project directory
  • Open Terminal
  • build mvn clean package
  • run mvn spring-boot:run
  • Open Another Terminal, you can test
  • curl http://localhost:8080
  • curl http://localhost:8080/
  • Related