【问题标题】:Spring WebClient without the springboot-starter-web-flux没有 spring boot-starter-webflux 的 Spring WebClient
【发布时间】:2021-09-10 01:33:44
【问题描述】:

我的是一个 Spring Boot 应用程序,但不使用任何 Web 功能。它只是用作命令行应用程序,将由 CRON 在预定的时间间隔内触发,然后它执行作业并死掉(从未运行过 web 应用程序

在这项工作中,我需要进行 REST 调用,并且需要使用 WebClient 来进行相同的调用。下面是我用来引入 WebClient 的依赖项

implementation 'org.springframework.boot:spring-boot-starter-webflux'

但是这种依赖关系使我的应用程序保持运行,并且在工作完成后不允许工作终止。我尝试从上述依赖项中排除 netty,但这会导致以下错误

原因:org.springframework.context.ApplicationContextException:由于缺少 ReactiveWebServerFactory bean,无法启动 ReactiveWebApplicationContext。

如何在使用WebClient的同时不使用任何Web功能?

注意:我尝试在我的属性文件中提供spring.main.web-application-type=none,这有助于我排除网络功能。但这是唯一的方法吗?

【问题讨论】:

    标签: spring spring-boot spring-webflux


    【解决方案1】:

    这不是唯一的方法,但我认为它肯定是最简单的。

    您可以手动配置所使用的应用程序上下文的类型并排除一些自动配置类,但设置 web-application-type 属性或在 SpringApplicationSpringApplicationBuilder 上以编程方式配置它会以更少的代码和配置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-28
      • 2020-07-02
      • 1970-01-01
      • 2017-08-28
      • 2018-09-27
      • 2018-12-24
      • 2018-05-09
      相关资源
      最近更新 更多