bounty还有4天到期。回答此问题可获得+250声望奖励。PacificNW_Lover正在寻找一个答案从一个有信誉的来源。
在YouTube上观看了Spring + Kotlin = Modern + Reactive + Productive演示!通过使用https://start.spring.io/..创建基于Kotlin的Spring Web Flux Reactive应用。
使用这些依赖项生成项目(请注意Sping 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()
}
当我最初尝试在macOS上使用gradle build
和./gradlew build
(都使用IntelliJ和命令行)构建它时(在下载和解压缩zip文件后)出现错误。
当我克隆这个演示所基于的GitHub project时,我得到了同样的错误:
使用gradle build
(在使用 Package 器时也会失败,例如./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和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
时,我不能构建这个?
这是我正在尝试构建的项目:
https://github.com/jamesward/nks/tree/main/bootiful
docker守护进程正在运行,我运行了以下命令(在我尝试使用gradle build
和/或./gradlew build
构建之前)docker ps
:
输出:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
就像我说的,当我在http://start.spring.io中创建一个新项目时,也会发生这种情况。这是因为TestContainers吗?TestContainers或任何其他配置是否需要设置任何步骤/先决条件?
运行位于此处的Unix shell脚本后:
https://github.com/jamesward/nks/blob/main/postgres.sh
然后检查docker daemon:
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
Unix shell脚本的结尾:
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)
如果其他人能尝试复制这个问题,将不胜感激...
请记住,当我使用YouTube演示视频中的演示者使用的相同依赖项(参见上面的屏幕截图)通过http://start.spring.io创建项目时,这不起作用,当我使用新的git clone
时,作者的code也不起作用...
2条答案
按热度按时间voj3qocg1#
根据您的stacktrace,您遇到的问题与Docker有关:
DockerClientProviderStrategy
中的第256行代码如下:你有机会尝试这里提供的说明吗?https://www.testcontainers.org/on_failure.htmlhttps://www.testcontainers.org/supported_docker_environment/
我的建议是尝试更新或重新安装Docker。这可能会解决这个问题。
5rgfhyps2#
运行
./gradlew build --info
后,输出类似于:通过从命令行运行以下命令修复了此问题:
sudo ln -s $HOME/.docker/run/docker.sock /var/run/docker.sock
礼貌的评论有人回答了这个帖子:
Test Container test cases are failing due to "Could not find a valid Docker environment"
现在,当我运行
./gradlew build
时: