大佬教程收集整理的这篇文章主要介绍了遵循此 Kotlin Spring BOOT 应用程序不起作用,,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在学习本教程:
https://kotlinlang.org/docs/jvm-spring-boot-restful.html#proceed-to-the-next-tutorial
这是一个很好的一步一步肯定。我的 intelliJ 项目编译并运行。
这是我的构建文件:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
ID("org.springframework.boot") version "2.4.8"
ID("io.spring.dependency-management") version "1.0.11.RELEASE"
kotlin("jvm") version "1.4.32"
kotlin("plugin.spring") version "1.4.32"
}
group = "com.example.itemtracker"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8
repositorIEs {
mavenCentral()
mavenLocal()
}
dependencIEs {
implementation("org.springframework.boot:spring-boot-starter")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
testImplementation("org.springframework.boot:spring-boot-starter-test")
implementation("org.springframework:spring-web:5.3.8")
implementation("org.jetbrains.kotlinx:kotlinx-coroutInes-core:1.4.1")
implementation("org.springframework.boot:spring-boot-starter-tomcat:2.5.0")
}
tasks.withType<KotlinCompile> {
kotlinoptions {
freeCompilerArgs = listof("-XJsr305=Strict")
jvmTarget = "1.8"
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
其他一切看起来都像本教程。
问题是当我输入 localhost:8080 - 我得到这个 404。控制器在同一个类中。我不知道为什么会出现 404。
有人知道为什么会发生这种情况吗?
更新:
我创建了另一个使用 Maven 的 Kotlin 项目并且它可以工作。但是 Gradle 版本仍然无法运行。
POM 是:
<?xml version="1.0" enCoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLscheR_527_11845@a-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:scheR_527_11845@aLOCATIOn="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactID>mainModule</artifactID>
<groupID>me.scmacdon</groupID>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>mainModule</name>
<parent>
<groupID>org.springframework.boot</groupID>
<artifactID>spring-boot-starter-parent</artifactID>
<version>2.0.4.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<propertIEs>
<project.build.sourceEnCoding>UTF-8</project.build.sourceEnCoding>
<kotlin.code.style>official</kotlin.code.style>
<kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
</propertIEs>
<repositorIEs>
<repository>
<ID>mavenCentral</ID>
<url>https://repo1.maven.org/maven2/</url>
</repository>
</repositorIEs>
<build>
<sourceDirectory>src/main/kotlin</sourceDirectory>
<testsourceDirectory>src/test/kotlin</testsourceDirectory>
<plugins>
<plugin>
<groupID>org.jetbrains.kotlin</groupID>
<artifactID>kotlin-maven-plugin</artifactID>
<version>1.4.32</version>
<EXECUTIONS>
<execution>
<ID>compile</ID>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<ID>test-compile</ID>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</EXECUTIONS>
</plugin>
<plugin>
<artifactID>maven-surefire-plugin</artifactID>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
<dependencIEs>
<dependency>
<groupID>org.jetbrains.kotlin</groupID>
<artifactID>kotlin-test-junit</artifactID>
<version>1.4.32</version>
<scope>test</scope>
</dependency>
<dependency>
<groupID>org.jetbrains.kotlin</groupID>
<artifactID>kotlin-stdlib-jdk8</artifactID>
<version>1.4.32</version>
</dependency>
<dependency>
<groupID>org.junit.jupiter</groupID>
<artifactID>junit-jupiter-API</artifactID>
<version>5.4.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupID>org.jetbrains.kotlin</groupID>
<artifactID>kotlin-reflect</artifactID>
<version>1.1.51</version>
</dependency>
<dependency>
<groupID>org.junit.jupiter</groupID>
<artifactID>junit-jupiter-ENGIne</artifactID>
<version>5.4.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupID>org.junit.platform</groupID>
<artifactID>junit-platform-commons</artifactID>
<version>1.4.0</version>
</dependency>
<dependency>
<groupID>org.junit.platform</groupID>
<artifactID>junit-platform-launcher</artifactID>
<version>1.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupID>junit</groupID>
<artifactID>junit</artifactID>
<version>4.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupID>org.springframework.boot</groupID>
<artifactID>spring-boot-starter-thymeleaf</artifactID>
</dependency>
<dependency>
<groupID>org.springframework.boot</groupID>
<artifactID>spring-boot-starter-web</artifactID>
</dependency>
<dependency>
<groupID>org.springframework.boot</groupID>
<artifactID>spring-boot-starter-test</artifactID>
<scope>test</scope>
<exclusions>
<exclusion>
<groupID>org.junit.vintage</groupID>
<artifactID>junit-vintage-ENGIne</artifactID>
</exclusion>
</exclusions>
</dependency>
</dependencIEs>
</project>
以下 Gradle 构建文件解决了这个问题:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "2.4.8"
id("io.spring.dependency-management") version "1.0.11.RELEASE"
kotlin("jvm") version "1.4.32"
kotlin("plugin.spring") version "1.4.32"
}
group = "com.example"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_11
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jdbc")
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")
runtimeOnly("com.h2database:h2")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=Strict")
jvmTarget = "1.8"
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
以上是大佬教程为你收集整理的遵循此 Kotlin Spring BOOT 应用程序不起作用,全部内容,希望文章能够帮你解决遵循此 Kotlin Spring BOOT 应用程序不起作用,所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。