Home > OS >  Whitelabel Error on a simple Hello World app spring boot
Whitelabel Error on a simple Hello World app spring boot

Time:04-29

When I try to go localhost:8080/ I got whitelabel error.

My Controller:

package com.example.demo;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class FormController {

    @RequestMapping("/")
    public String login() {
        return "Hello, World!";
    }
}

I tried using different ports too.

My dependencies: Spring Web, Spring Web Services, Jersey, Spring Data JPA and H2 database.

I am about to lose it so please help me.

CodePudding user response:

Short answer:

 @ResponseBody
 @RequestMapping("/")
    public String login() {
        return "Hello, World!";
    }

Long answer:

Without @ResponseBody because you have @Controller and Spring-Mvc, it will try to use the String that you return "Hello World!" and match it with a jsp view that is named "Hello World!" which obviously does not exist and therefore you get the whitelabel error.

Adding @ResponseBody Spring-Mvc will not try to find a view with this name but will return just this simple response as String.

  • Related