【问题标题】:bazel run works, but building deploy JAR fails due to missing dependenciesbazel run 有效,但由于缺少依赖项,构建部署 JAR 失败
【发布时间】:2020-01-23 18:33:39
【问题描述】:

这里是 Java/Bazel 新手。我有一个使用 Spring Boot 的项目(并使用 rules_jvm_external 管理外部依赖项)。

我能够成功运行 bazel run,但是当我尝试构建 _deploy.jar 时,应用程序失败并出现以下错误:

11:48:11.913 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:156)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
    at com.flexport.originops.OriginOpsApplication.main(OriginOpsApplication.java:18)
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:203)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:179)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:153)
    ... 8 common frames omitted  

似乎某些依赖项没有被可部署 JAR 拾取,但在我运行 bazel run 时被拾取。

这是我的(截断的)BUILD 文件:

filegroup(
    name = "java_files",
    srcs = glob(["src/main/java/**/*.java"]),
)
filegroup(
    name = "java_test_files",
    srcs = glob(["src/test/java/com/**/*.java"]),
)
java_library(
    name = "lib",
    srcs = [
        ":java_files",
    ],
    resources = glob(["src/main/resources/**"]),
    deps = [
        # Plugins and internal dependencies
        "//build-utils/lombok",
        "//build-utils/mapstruct",
        ...
        # External dependencies
        "@com_google_protobuf//:protobuf_java",
        "@maven//:com_baomidou_mybatis_plus_annotation",
        "@maven//:com_baomidou_mybatis_plus_boot_starter",
        "@maven//:com_baomidou_mybatis_plus_core",
        "@maven//:com_baomidou_mybatis_plus_extension",
        "@maven//:com_fasterxml_jackson_core_jackson_annotations",
        "@maven//:com_fasterxml_jackson_core_jackson_core",
        "@maven//:com_fasterxml_jackson_core_jackson_databind",
        "@maven//:com_fasterxml_jackson_module_jackson_module_jsonSchema",
        "@maven//:com_github_rholder_guava_retrying",
        "@maven//:com_google_code_findbugs_jsr305",
        "@maven//:com_google_guava_guava",
        "@maven//:com_hubspot_HorizonCore",
        "@maven//:com_hubspot_algebra",
        "@maven//:com_hubspot_slack_slack_base",
        "@maven//:com_hubspot_slack_slack_java_client",
        "@maven//:io_springfox_springfox_bean_validators",
        "@maven//:io_springfox_springfox_core",
        "@maven//:io_springfox_springfox_spi",
        "@maven//:io_springfox_springfox_spring_web",
        "@maven//:io_springfox_springfox_swagger2",
        "@maven//:io_springfox_springfox_swagger_ui",
        "@maven//:io_swagger_swagger_annotations",
        "@maven//:jakarta_validation_jakarta_validation_api",
        "@maven//:javax_validation_validation_api",
        "@maven//:org_apache_tomcat_tomcat_annotations_api",
        "@maven//:org_aspectj_aspectjweaver",
        "@maven//:org_flywaydb_flyway_core",
        "@maven//:org_javassist_javassist",
        "@maven//:org_mapstruct_mapstruct",
        "@maven//:org_mapstruct_mapstruct_processor",
        "@maven//:org_mybatis_mybatis",
        "@maven//:org_mybatis_mybatis_spring",
        "@maven//:org_postgresql_postgresql",
        "@maven//:org_reflections_reflections",
        "@maven//:org_slf4j_slf4j_api",
        "@maven//:org_springframework_boot_spring_boot",
        "@maven//:org_springframework_boot_spring_boot_autoconfigure",
        "@maven//:org_springframework_boot_spring_boot_configuration_processor",
        "@maven//:org_springframework_boot_spring_boot_devtools",
        "@maven//:org_springframework_boot_spring_boot_starter_actuator",
        "@maven//:org_springframework_boot_spring_boot_starter_aop",
        "@maven//:org_springframework_boot_spring_boot_starter_web",
        "@maven//:org_springframework_spring_beans",
        "@maven//:org_springframework_spring_context",
        "@maven//:org_springframework_spring_tx",
        "@maven//:org_springframework_spring_web",
        "@maven//:org_springframework_spring_webmvc",
    ],
)
java_binary(
    # not the real names
    name = "app",
    main_class = "com.my.org.Application",
    runtime_deps = [
        ":lib",
    ],
)

在黑暗中猛烈抨击,我认为这可能与我的应用程序所依赖的 Java 插件有关,但我不确定为什么这会导致 Spring Boot 无法启动。有人知道会发生什么吗?

【问题讨论】:

    标签: java spring-boot bazel


    【解决方案1】:

    你试过https://github.com/salesforce/bazel-springboot-rule/吗?

    我能够在此处获得一个带有 rules_jvm_external 的“hello world”SpringBoot 应用程序:https://github.com/thundergolfer/the-one-true-bazel-monorepo/commits/jonathon/spring-boot-backend

    我在这里发布了关于 rules_jvm_external 与 github.com/salesforce/bazel-springboot-rule 兼容性的问题:https://github.com/salesforce/bazel-springboot-rule/issues

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-13
      • 2017-07-19
      • 1970-01-01
      • 1970-01-01
      • 2018-08-10
      • 2015-04-30
      • 1970-01-01
      相关资源
      最近更新 更多