前提・実現したいこと
現在業務で、JavaのフレームワークであるSpring Bootを利用して、Webアプリケーションの開発をしています。
概要を理解するため、Spring bootの公式ページのチュートリアルを参照しながら簡単なブログを作成しようとしました。
発生している問題・エラーメッセージ
上記チュートリアルでWriting your first Kotlin controller までソースコードを記載していたのですが、以下の記載に従いメイン関数を実行して、アプリケーションを立ち上げ、localhostに接続しようとしたところ、404エラーが返ってきてしまいました。
Start the web application by running the main function of BlogApplication.kt, and go to http://localhost:8080/, you should see a sober web page with a "Blog" headline.
エラーメッセージ
This application has no explicit mapping for /error, so you are seeing this as a fallback. Sun Jan 26 18:42:45 GMT+09:00 2020 There was an unexpected error (type=Not Found, status=404). No message available
該当のソースコード
BlogApplication
1package com.example.blog 2 3import org.springframework.boot.autoconfigure.SpringBootApplication 4import org.springframework.boot.runApplication 5 6@SpringBootApplication 7class BlogApplication 8 9fun main(args: Array<String>) { 10 runApplication<BlogApplication>(*args) 11} 12
HtmlController
1package com.example.blog.controller 2 3import org.springframework.stereotype.Controller 4import org.springframework.ui.Model 5import org.springframework.ui.set 6import org.springframework.web.bind.annotation.GetMapping 7 8@Controller 9class HtmlController { 10 11 @GetMapping("/") 12 fun blog(model: Model): String { 13 model["title"] = "Blog" 14 return "blog" 15 } 16 17}
試したこと
こちらのStackoverflowの質問を参考にして、メインクラスがコントローラーファイルより上にくるフォルダ構成でなくてはならないということでしたので、メインクラスとコントローラーファイルを以下の構成にし直しました。
- メインクラス → com/example/blog/BlogApplication.kt
- コントローラファイル → com/example/blog/controller/HtmlController.kt
しかし、エラーは解消していません。
補足情報(FW/ツールのバージョンなど)
どういったツールのバージョンを載せればよいのかわからないため、プラグイン等のバージョンが記載されているbuild.gradle.ktsのコードを載せておきます。
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { id("org.springframework.boot") version "2.2.4.RELEASE" id("io.spring.dependency-management") version "1.0.9.RELEASE" kotlin("jvm") version "1.3.61" kotlin("plugin.spring") version "1.3.61" kotlin("plugin.jpa") version "1.3.61" } group = "com.example" version = "0.0.1-SNAPSHOT" java.sourceCompatibility = JavaVersion.VERSION_1_8 val developmentOnly by configurations.creating configurations { runtimeClasspath { extendsFrom(developmentOnly) } } repositories { mavenCentral() } dependencies { implementation("org.springframework.boot:spring-boot-starter-data-jpa") implementation("org.springframework.boot:spring-boot-starter-mustache") implementation("org.springframework.boot:spring-boot-starter-web") implementation("com.fasterxml.jackson.module:jackson-module-kotlin") implementation("org.jetbrains.kotlin:kotlin-reflect") implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") developmentOnly("org.springframework.boot:spring-boot-devtools") runtimeOnly("com.h2database:h2") testImplementation("org.springframework.boot:spring-boot-starter-test") { exclude(group = "org.junit.vintage", module = "junit-vintage-engine") } } tasks.withType<Test> { useJUnitPlatform() } tasks.withType<KotlinCompile> { kotlinOptions { freeCompilerArgs = listOf("-Xjsr305=strict") jvmTarget = "1.8" } }
初めての質問で抽象的になってしまい申し訳ありません。
どうかよろしくお願いします。
###追記(2019/1/26)
回答1件
あなたの回答
tips
プレビュー