我最近开始使用 gradle 并尝试在我的 mac 机器上使用 gradle 运行 spring boot 应用程序。
当我尝试进行本地构建时,出现以下错误:
我的 build.gradle 是默认的,它是从 Spring Initializr 下载的,几乎没有依赖项。
plugins {
id 'org.springframework.boot' version '2.1.7.RELEASE'
id 'io.spring.dependency-management' version '1.0.7.RELEASE'
id 'java'
}
group = 'com.ank'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
}
Run Code Online (Sandbox Code Playgroud)
我的 JAVA_HOME 位于路径:/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home
我尝试在 Intellij、Eclipse 和终端中通过gradle --stacktrace. 它到处都失败并出现相同的错误。
我的gradle版本是5.6。
我正在从我的 Spring Boot 应用程序调用不同的其他 Web 服务。为了提高性能而不是顺序调用它们,我想实现CompletableFuture.supplyAsync()异步执行。
我正在调用的服务,其中一些是内部的,一些是外部的。因此,对于内部,我直接调用它们的 api 接口,这些接口存在于 Maven 依赖项中,而对于外部接口,我正在使用javax.ws.rs.client.WebTarget
在实现调用时,CompletableFuture.supplyAsync()内部的客户端类会成功执行,而具有依赖关系的客户端类则会WebTarget因未创建 bean 而@Inject失败。scopedTarget.XXService_nameXX_wt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.charityserv_wt': Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.ws.rs.client.WebTarget]: Factory method 'target' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.coreContext': Scope 'request' is not active for the current thread
Run Code Online (Sandbox Code Playgroud)
调用代码:
CompletableFuture<SearchResult> future = CompletableFuture.supplyAsync(() -> searchServiceClientImpl.getsearchSearchRequest(encryptedAccountNumber));
Run Code Online (Sandbox Code Playgroud)
服务客户端类:
@Component
public class …Run Code Online (Sandbox Code Playgroud)