调用webClient请求时出现IllegalStateException



我的应用程序是一个非web Spring启动应用程序,使用WebClient进行内部get调用。

每次启动它时,它都会返回java.lang.IllegalStateException: executor not accepting a task

问题与web客户端调用有关:当我执行block((时,一切都正常。当我试图让它保持被动时,它会抛出一个异常。

这是我的主要方法:

public static void main(String[] args) {
SpringApplication app = new SpringApplication(Myapp.class);
app.setBannerMode(Banner.Mode.OFF);
app.run(args);
}
@Override
public void run(String... args) throws Exception {
///something that calls a webclient
exit(0);
}

这是我的网络客户端电话:

@PostConstruct
private void init() {
log.debug(String.format("diagram path %s", diagramPath));
this.client = WebClient.builder()
.baseUrl("blablabla")
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.build();
}
public Mono<String> getDiagram() {
return client
.get()
.uri("/")
.retrieve()
.bodyToMono(MyResponse.class);

以下是异常跟踪:

at io.netty.resolver.AddressResolverGroup.getResolver(AddressResolverGroup.java:60) ~[netty-resolver-4.1.43.Final.jar:4.1.43.Final]
at io.netty.bootstrap.Bootstrap.doResolveAndConnect0(Bootstrap.java:194) ~[netty-transport-4.1.43.Final.jar:4.1.43.Final]
at io.netty.bootstrap.Bootstrap.access$000(Bootstrap.java:48) ~[netty-transport-4.1.43.Final.jar:4.1.43.Final]
at io.netty.bootstrap.Bootstrap$1.operationComplete(Bootstrap.java:182) ~[netty-transport-4.1.43.Final.jar:4.1.43.Final]
at io.netty.bootstrap.Bootstrap$1.operationComplete(Bootstrap.java:168) ~[netty-transport-4.1.43.Final.jar:4.1.43.Final]
at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:577) ~[netty-common-4.1.43.Final.jar:4.1.43.Final]
at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:551) ~[netty-common-4.1.43.Final.jar:4.1.43.Final]
at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:490) ~[netty-common-4.1.43.Final.jar:4.1.43.Final]
at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:615) ~[netty-common-4.1.43.Final.jar:4.1.43.Final]
at io.netty.util.concurrent.DefaultPromise.setSuccess0(DefaultPromise.java:604) ~[netty-common-4.1.43.Final.jar:4.1.43.Final]
at io.netty.util.concurrent.DefaultPromise.trySuccess(DefaultPromise.java:104) ~[netty-common-4.1.43.Final.jar:4.1.43.Final]
at io.netty.channel.DefaultChannelPromise.trySuccess(DefaultChannelPromise.java:84) ~[netty-transport-4.1.43.Final.jar:4.1.43.Final]
at io.netty.channel.AbstractChannel$AbstractUnsafe.safeSetSuccess(AbstractChannel.java:985) ~[netty-transport-4.1.43.Final.jar:4.1.43.Final]
at io.netty.channel.AbstractChannel$AbstractUnsafe.register0(AbstractChannel.java:505) ~[netty-transport-4.1.43.Final.jar:4.1.43.Final]
at io.netty.channel.AbstractChannel$AbstractUnsafe.access$200(AbstractChannel.java:416) ~[netty-transport-4.1.43.Final.jar:4.1.43.Final]
at io.netty.channel.AbstractChannel$AbstractUnsafe$1.run(AbstractChannel.java:475) ~[netty-transport-4.1.43.Final.jar:4.1.43.Final]
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163) ~[netty-common-4.1.43.Final.jar:4.1.43.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:510) ~[netty-common-4.1.43.Final.jar:4.1.43.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:518) ~[netty-transport-4.1.43.Final.jar:4.1.43.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$6.run(SingleThreadEventExecutor.java:1050) ~[netty-common-4.1.43.Final.jar:4.1.43.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.43.Final.jar:4.1.43.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.43.Final.jar:4.1.43.Final]
at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]

您的应用程序似乎处于关闭状态,因此Netty executor不接受任务(要执行的请求(。如果进程不是web应用程序,您如何保持它的运行?

AddressResolverGroup源代码

59. if (executor.isShuttingDown()) {
60.     throw new IllegalStateException("executor not accepting a task");
61. }

(注意:在@PostConstruct方法中实例化WebClient实例看起来不对(

相关内容

  • 没有找到相关文章

最新更新