Srping Boot Whitelabel Error Page

問題

剛纔在使用Spring Boot搭建微服務的時候,遇到一個問題,Spring Boot項目啓動後,在頁面打開http://localhost:8080/,報錯了,信息是:Whitelabel Error Page!


解決

看代碼說話,代碼如下:

package com.woxin.itsm;

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

/**
 * 應用入口
 */


@SpringBootApplication
public class ItsmApplication {


	@RequestMapping("/")
	public String index(){
		return "hello!";
	}


	public static void main(String[] args) {
		SpringApplication.run(ItsmApplication.class, args);
	}
}

其中下面一段時間原來是沒有的,是我後來加上的。

@RequestMapping("/")
	public String index(){
		return "hello!";
	}
而加了這段代碼,那對應的類就是Controller,且需要與頁面進行交互的,所以我想應該是少了什麼東西。然後在註解
@SpringBootApplication

前面加上另一個註解,

@RestController
再啓動就OK了。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章