简体   繁体   中英

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.

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.

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