在YouTube上跟随了Spring + Kotlin = Modern + Reactive + Productive个演示文稿!通过使用https://start.spring.io/..创建一个基于Kotlin的Spring Web Fluxreact 性应用程序.
使用这些依赖项生成了项目(请注意Spring Boot和Java版本):
这将生成build.gradle.kts
个文件:
plugins {
java
id("org.springframework.boot") version "3.0.6"
id("io.spring.dependency-management") version "1.1.0"
id("org.graalvm.buildtools.native") version "0.9.20"
}
group = "bootiful"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17
repositories {
mavenCentral()
}
extra["testcontainersVersion"] = "1.18.1"
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-r2dbc")
implementation("org.springframework.boot:spring-boot-starter-webflux")
runtimeOnly("org.postgresql:postgresql")
runtimeOnly("org.postgresql:r2dbc-postgresql")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("io.projectreactor:reactor-test")
testImplementation("org.testcontainers:junit-jupiter")
testImplementation("org.testcontainers:postgresql")
testImplementation("org.testcontainers:r2dbc")
}
dependencyManagement {
imports {
mavenBom("org.testcontainers:testcontainers-bom:${property("testcontainersVersion")}")
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
当我最初try 在MacOS上使用gradle build
&;./gradlew build
(两者都使用IntelliJ&;命令行)构建它时(在下载和解压压缩文件之后),遇到错误.
当我克隆本演示文稿所基于的GitHub project时,我收到了同样的错误:
使用gradle build
(使用包装器时也失败,例如./gradlew build
):
KotlinApplicationTests > contextLoads() FAILED
org.junit.jupiter.api.extension.ParameterResolutionException at ParameterResolutionUtils.java:159
Caused by: java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:142
Caused by: org.springframework.beans.factory.BeanCreationException at AbstractAutowireCapableBeanFactory.java:1770
Caused by: org.springframework.r2dbc.connection.init.UncategorizedScriptException at DatabasePopulator.java:65
Caused by: org.springframework.dao.DataAccessResourceFailureException at ConnectionFactoryUtils.java:90
Caused by: java.util.concurrent.CompletionException at CompletableFuture.java:315
Caused by: java.lang.IllegalStateException at DockerClientProviderStrategy.java:256
使用gradle build --warning-mode=all
:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.0.5)
2023-05-12T13:12:54.326-07:00 INFO 50318 --- [ main] bootiful.kotlin.KotlinApplicationTests : Starting KotlinApplicationTests using Java 20.0.1 with PID 50318 (/Users/pnwlover/nks/bootiful/build/classes/kotlin/test started by pnwlover/ in /Users/pnwlover/nks/bootiful)
2023-05-12T13:12:54.328-07:00 INFO 50318 --- [ main] bootiful.kotlin.KotlinApplicationTests : No active profile set, falling back to 1 default profile: "default"
2023-05-12T13:12:55.184-07:00 INFO 50318 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data R2DBC repositories in DEFAULT mode.
2023-05-12T13:12:55.378-07:00 INFO 50318 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 187 ms. Found 1 R2DBC repository interfaces.
> Task :compileAotTestJava
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
> Task :test
The org.gradle.util.GFileUtils type has been deprecated. This is scheduled to be removed in Gradle 9.0. Consult the upgrading guide for further information: https://docs.gradle.org/8.1.1/userguide/upgrading_version_7.html#org_gradle_util_reports_deprecations
KotlinApplicationTests > contextLoads() FAILED
org.junit.jupiter.api.extension.ParameterResolutionException at ParameterResolutionUtils.java:159
Caused by: java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:142
Caused by: org.springframework.beans.factory.BeanCreationException at AbstractAutowireCapableBeanFactory.java:1770
Caused by: org.springframework.r2dbc.connection.init.UncategorizedScriptException at DatabasePopulator.java:65
Caused by: org.springframework.dao.DataAccessResourceFailureException at ConnectionFactoryUtils.java:90
Caused by: java.util.concurrent.CompletionException at CompletableFuture.java:315
Caused by: java.lang.IllegalStateException at DockerClientProviderStrategy.java:256
在我本地系统中设置的Gradle、Java和amp;Kotlin版本:
gradle -v
------------------------------------------------------------
Gradle 8.1.1
------------------------------------------------------------
Build time: 2023-04-21 12:31:26 UTC
Revision: 1cf537a851c635c364a4214885f8b9798051175b
Kotlin: 1.8.10
Groovy: 3.0.15
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 20.0.1 (Oracle Corporation 20.0.1+9-29)
OS: Mac OS X 12.6.5 x86_64
java -version
java version "17.0.6" 2023-01-17 LTS
Java(TM) SE Runtime Environment (build 17.0.6+9-LTS-190)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.6+9-LTS-190, mixed mode, sharing)
❯ kotlinc -version
info: kotlinc-jvm 1.8.21 (JRE 20.0.1+9-29)
为什么当我从存储库中创建一个新的git clone
%时,我不能构建这个?
这是我正在try 构建的项目:
https://github.com/jamesward/nks/tree/main/bootiful个
Docker守护进程正在运行,我运行了以下命令(在try 使用gradle build
和/或./gradlew build
构建之前)
docker ps
:
输出:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
就像,我说过,当我从http://start.spring.io以内创建一个新项目时,也发生了这种情况.这是由于TestContainers造成的吗?设置TestContainers或任何其他配置是否需要任何步骤/前提条件?
运行位于以下位置的Unixshell 脚本后:
https://github.com/jamesward/nks/blob/main/postgres.sh个
然后判断停靠器守护进程:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d12e7449a853 postgres:13.3 "docker-entrypoint.s…" 36 seconds ago Up 33 seconds 0.0.0.0:5432->5432/tcp my-postgres
Unixshell 脚本的尾部:
PostgreSQL init process complete; ready for start up.
2023-05-15 07:45:20.258 UTC [1] LOG: starting PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
2023-05-15 07:45:20.258 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2023-05-15 07:45:20.259 UTC [1] LOG: listening on IPv6 address "::", port 5432
2023-05-15 07:45:20.264 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2023-05-15 07:45:20.272 UTC [66] LOG: database system was shut down at 2023-05-15 07:45:20 UTC
2023-05-15 07:45:20.285 UTC [1] LOG: database system is ready to accept connections
^C2023-05-15 08:00:13.887 UTC [1] LOG: received fast shutdown request
2023-05-15 08:00:13.890 UTC [1] LOG: aborting any active transactions
2023-05-15 08:00:13.894 UTC [1] LOG: background worker "logical replication launcher" (PID 72) exited with exit code 1
2023-05-15 08:00:13.894 UTC [67] LOG: shutting down
2023-05-15 08:00:13.919 UTC [1] LOG: database system is shut down
当我向内看时:../build/reports/tests/test/index.html
:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'r2dbcScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/R2dbcInitializationConfiguration.class]: Failed to execute database script
at app//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1770)
at app//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:598)
at app//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520)
如果其他人能try 复制这一问题,我将不胜感激.
记住,当我通过http://start.spring.io创建一个项目时,使用YouTube演示视频中的演示者使用的相同依赖关系(见上面的屏幕截图),这不起作用;当我通过新的git clone
创建项目时,作者的code也不起作用.