bazel运行正常,但是由于缺少依赖项,因此构建部署JAR失败

时间:2019-12-02 20:43:57

标签: java spring-boot bazel

Java / Bazel noobie在这里。我有一个使用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时这些依赖关系却被拾取。

这是我的(已截断的)构建文件:

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无法启动。有人知道会发生什么吗?

1 个答案:

答案 0 :(得分:0)

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

我能够在此处https://github.com/thundergolfer/the-one-true-bazel-monorepo/commits/jonathon/spring-boot-backend

上获得一个带有rules_jvm_external的“ hello world” SpringBoot应用程序

我在此处发布了一个有关rules_jvm_external与github.com/salesforce/bazel-springboot-rule的兼容性的问题:https://github.com/salesforce/bazel-springboot-rule/issues