【问题标题】:spring-boot-starter-web with web application type NONE. Why?web 应用程序类型为 NONE 的 spring-boot-starter-web。为什么?
【发布时间】:2020-09-15 02:58:42
【问题描述】:

我以前从未使用过CommandLineRunner,因为我一直在编写 Web 服务器。这次我正在构建一个微服务(CRON 作业),它会唤醒,进行一些休息和数据库调用,然后停止。

对于这个项目,和其他项目一样,最初我有以下依赖项:

implementation "org.springframework.boot:spring-boot-starter-web:$springBootVersion"

直到我发现有一个叫做 CommandLineRunner 的东西,并且由于我不需要运行 Web 服务器,我实际上可以通过 .setWebApplicationType(WebApplicationType.NONE); 将其关闭

现在我想知道如果我们关闭其网络服务器,包含 spring-boot-starter-web 的意义何在?我使用 Spring Boot 框架默认使用它的依赖项(比如 jackson 等)以及它的依赖项管理框架。

(旁注:我试图转移到sprint-boot-starter,但我无法解决以下问题,所以我想我继续使用spring-boot-starter-web

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.http.converter.json.Jackson2ObjectMapperBuilder)

【问题讨论】:

    标签: spring-boot


    【解决方案1】:

    我们可以看到spring-boot-starter-web包括:

    spring-boot-starter
    spring-boot-starter-json
    spring-boot-starter-tomcat
    spring-web
    spring-webmvc
    hibernate-validator
    

    查看Jackson2ObjectMapperBuilder 所在的位置,我们可以看到它位于spring-web 中,而spring-boot-starter-json 包含在其中。

    我怀疑如果您添加 spring-boot-starter-json,您将更接近在没有 Web 服务器组件的情况下运行您的服务。

    Maven 依赖分析器可以在以后省去相当多的麻烦,方法是从顶部开始并查看每个 POM 文件包含的内容。

    【讨论】:

      猜你喜欢
      • 2020-05-23
      • 1970-01-01
      • 2017-01-23
      • 2016-01-29
      • 1970-01-01
      • 2017-02-19
      • 2019-10-28
      • 1970-01-01
      • 2020-07-02
      相关资源
      最近更新 更多