実現したいこと
htmlファイルを表示したい
発生している問題・分からないこと
htmlが表示されず、エラーページがないという画面が表示される
(LibraryControllerの返却までは正常動作を確認済みで、その後のどこかで落ちている模様)
■リクエストURL
http://localhost:8080/
エラーメッセージ
error
1Whitelabel Error Page 2This application has no explicit mapping for /error, so you are seeing this as a fallback. 3 4Sun Feb 16 19:15:43 GMT+09:00 2025 5There was an unexpected error (type=Not Found, status=404).
該当のソースコード
java(アプリ起動)
1package com.architect.webapplication; 2 3import org.springframework.boot.SpringApplication; 4import org.springframework.boot.autoconfigure.SpringBootApplication; 5 6 7@SpringBootApplication 8public class WebapplicationApplication { 9 10 public static void main(String[] args) { 11 SpringApplication.run(WebapplicationApplication.class, args); 12 } 13 14} 15
java(コントローラ)
1package com.architect.webapplication.Controller; 2import org.springframework.ui.Model; 3import org.springframework.stereotype.Controller; 4import org.springframework.web.bind.annotation.GetMapping; 5 6@Controller 7public class LibraryController { 8 9 @GetMapping("/") 10 public String library(Model model) { 11 model.addAttribute("message", "Hello World!!"); 12 return "library"; 13 } 14} 15
html
1<!DOCTYPE html> 2<html lang="ja" xmlns:th="http://www.thymeleaf.org"> 3<head> 4 <meta http-equiv="Content-Type" content="text/html;" charset="UTF-8"> 5 <title>図書館</title> 6</head> 7<body> 8<h2>図書貸出・返却</h2> 9 <button id="btnBorrow">貸出</button> 10 <button id="btnReturn">返却</button> 11 <br> 12<h2>図書一覧</h2> 13 <table border="1"> 14 <tr> 15 <th>書籍ID</th> 16 <th>書籍名</th> 17 </tr> 18 <tr> 19 <td>ID0001</td> 20 <td>君の名は</td> 21 </tr> 22 </table> 23</body> 24</html> 25
properties
1spring.application.name=webapplication 2 3spring.thymeleaf.prefix=classpath:/templates/ 4spring.thymeleaf.mode=HTML 5spring.thymeleaf.cache=false
pom.xml
1<?xml version="1.0" encoding="UTF-8"?> 2<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4 <modelVersion>4.0.0</modelVersion> 5 <parent> 6 <groupId>org.springframework.boot</groupId> 7 <artifactId>spring-boot-starter-parent</artifactId> 8 <version>3.4.2</version> 9 <relativePath/> <!-- lookup parent from repository --> 10 </parent> 11 <groupId>com.architect</groupId> 12 <artifactId>webapplication</artifactId> 13 <version>0.0.1-SNAPSHOT</version> 14 <name>webapplication</name> 15 <description>Demo project for Spring Boot</description> 16 <url/> 17 <licenses> 18 <license/> 19 </licenses> 20 <developers> 21 <developer/> 22 </developers> 23 <scm> 24 <connection/> 25 <developerConnection/> 26 <tag/> 27 <url/> 28 </scm> 29 <properties> 30 <java.version>17</java.version> 31 </properties> 32 <dependencies> 33 <dependency> 34 <groupId>org.springframework.boot</groupId> 35 <artifactId>spring-boot-starter-web</artifactId> 36 </dependency> 37 <dependency> 38 <groupId>org.springframework.session</groupId> 39 <artifactId>spring-session-core</artifactId> 40 </dependency> 41 42 <dependency> 43 <groupId>org.springframework.boot</groupId> 44 <artifactId>spring-boot-starter-test</artifactId> 45 <scope>test</scope> 46 </dependency> 47 </dependencies> 48 <dependency> 49 <groupId>org.springframework.boot</groupId> 50 <artifactId>spring-boot-starter-thymeleaf</artifactId> 51 </dependency> 52 53 <build> 54 <plugins> 55 <plugin> 56 <groupId>org.springframework.boot</groupId> 57 <artifactId>spring-boot-maven-plugin</artifactId> 58 </plugin> 59 </plugins> 60 <resources> 61 <resource> 62 <directory>src/main/resources</directory> 63 <filtering>true</filtering> 64 </resource> 65 </resources> 66 </build> 67 68</project> 69
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
自身の仮説として、
コントローラがhtmlファイルを見つけられていないのでは?と考えているも、
フォルダ階層も調べた限りでは適切であり、何が問題か見当もついていない状況です。
補足
特になし

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2025/02/16 12:21