IntelliJ IDEAでクラスやメソッドが使えない

前提

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

package in.techcamp.firstapp; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class FirstappApplication { public static void main(String[] args) { SpringApplication.run(FirstappApplication.class, args); } }

src/main/java/in.techcamp.firstapp/Postcontroller

package in.techcamp.firstapp; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller public class PostController { @GetMapping("/hello") @ResponseBody public String showHello(){ return "<h1>Hello World!</h1>"; } }

試したこと

・キャッシュを破棄して再起動

補足情報(FW/ツールのバージョンなど)

・spring initializrから新規プロジェクトを作成(Gradle Project)
・spring boot 2.7.3

コメントを投稿

0 コメント