SpringBootの初歩の初歩で詰まった話(解決済)
どーも、ふぎとです。
今回は初歩的なエラーの備忘録です。
具体的には「SpringBootとThymeleafを使って、
http://localhost:8080 に"Hello World"と
表示するMVCアプリケーション試作時に出会った
whitelabel error pageへの対処」の記録です。
まずはプロジェクトの作成
こちらの記事通りに作成しました。
そのまま記事に従ってサーバ起動、localhostのページへ……。
エラーページがどーん
スクショ忘れましたが、早速エラーページに遭遇。
よくよく見てみると
"This application has no explicit mapping for /error"
とのこと。ふむ?
とりあえずエラーメッセージで検索
どうやらハマりがちなエラーのよう。
でも「依存関係にThymeleafを追加してみて」など
もうしてることに対する指摘おおめ…汗
これは自分で質問するしかないか……ん?
おや??
自分で作成したHelloController.javaと
この記事に載ってるControllerのソースと見比べていて違いを発見。
package com.example.web;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@RequestMapping("")
@Controller
public class PortalController {
@RequestMapping("")
public String index() {
System.out.println("aaa");
return "home";
}
}
package com.example.demo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class HelloController {
@RequestMapping("/")
public ModelAndView index(){
ModelAndView model = new ModelAndView();
model.setViewName("index");
return model;
}
}
Controllerアノテーションの前にRequestMappingアノテーション
付けてへん。
ひょっとしてこれか……?
半信半疑でRequestMappingを追加。すると……
いけた
Author And Source
この問題について(SpringBootの初歩の初歩で詰まった話(解決済)), 我々は、より多くの情報をここで見つけました https://qiita.com/FugitHora812/items/5e6a9b3ad4642742651f著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .