前提
IntelliJ IDEA CEで簡易アプリを作成しています。
クラスやメソッドが使用されないとエラーが発生しています。
※IntelliJを使うのは初めてです
実現したいこと
localhost:8080/helloとURLを入力した際に、
ブラウザに「Hello World」と文字が表示されるようにしたいです。
発生している問題・エラーメッセージ
下記のエラーが出て、localhost:8080/helloとURLを入力してもブラウザはWhitelabel Error Pageのままです
!PostControllerは使用されません !showHello()は使用されません
また、サーバーを停止した際に下記のエラー分が出ます。
Execution failed for task ':FirstappApplication.main()'. > Build cancelled while executing task ':FirstappApplication.main()' * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights.
該当のソースコード
src/main/java/in.techcamp.firstapp/FirstappApplication
1package in.techcamp.firstapp; 2 3import org.springframework.boot.SpringApplication; 4import org.springframework.boot.autoconfigure.SpringBootApplication; 5 6@SpringBootApplication 7public class FirstappApplication { 8 9 public static void main(String[] args) { 10 SpringApplication.run(FirstappApplication.class, args); 11 } 12 13}
src/main/java/in.techcamp.firstapp/Postcontroller
1package in.techcamp.firstapp; 2 3import org.springframework.stereotype.Controller; 4import org.springframework.web.bind.annotation.GetMapping; 5import org.springframework.web.bind.annotation.ResponseBody; 6 7@Controller 8public class PostController { 9 @GetMapping("/hello") 10 @ResponseBody 11 public String showHello(){ 12 return "<h1>Hello World!</h1>"; 13 } 14}
試したこと
・キャッシュを破棄して再起動
補足情報(FW/ツールのバージョンなど)
・spring initializrから新規プロジェクトを作成(Gradle Project)
・spring boot 2.7.3
あなたの回答
tips
プレビュー