gpt4 book ai didi

java - bazel run 有效,但构建部署 JAR 由于缺少依赖项而失败

转载 作者:太空宇宙 更新时间:2023-11-04 09:15:00 25 4
gpt4 key购买 nike

这里是 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 时却被拾取。

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

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

最佳答案

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

关于java - bazel run 有效,但构建部署 JAR 由于缺少依赖项而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59146399/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com