首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >bazel运行正常,但由于缺少依赖项,构建deploy JAR失败

bazel运行正常,但由于缺少依赖项,构建deploy JAR失败
EN

Stack Overflow用户
提问于 2019-12-03 04:43:57
回答 1查看 342关注 0票数 1

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

我可以成功运行bazel run,但当我尝试构建_deploy.jar时,应用程序失败,并显示以下错误:

代码语言:javascript
复制
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时获得的。

下面是我的(截断)构建文件:

代码语言:javascript
复制
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无法启动。有人知道可能会发生什么吗?

EN

回答 1

Stack Overflow用户

发布于 2020-01-23 18:33:40

你试过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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59146399

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档