'Whitelabel Error on a simple Hello World app spring boot
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.
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Panagiotis Bougioukos |
