gpt4 book ai didi

java - 我的 Spring Boot 应用程序加载后立即退出,不会出现错误

转载 作者:行者123 更新时间:2023-11-30 05:56:56 25 4
gpt4 key购买 nike

我正在将 Maven Spring Boot 应用程序转换为基于 bazel 的应用程序。我终于正确编译了它,但是一旦我运行它,它就退出了。服务器不会启动,但会打印 sprint boot 启动消息。

我认为这与 spring 无法找到 servlet 有关,但我对 java 很陌生,所以我不知道在哪里查找。

我无法从 JVM 获得任何关于它为何退出的可用信息。有没有办法增加 spring 的日志记录详细程度?

这是我的 Application.java

package com.example.abc;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class AbcClient {

public static void main(String[] args) {
SpringApplication.run(AbcClient.class, args);
}
}

我的工作空间文件

maven_jar(
name = "org_springframework_spring_core",
artifact = "org.springframework:spring-core:jar:5.1.1.RELEASE"
)

maven_jar(
name = "org_springframework_spring_beans",
artifact = "org.springframework:spring-beans:jar:5.1.1.RELEASE"
)

maven_jar(
name = "org_springframework_spring_context",
artifact = "org.springframework:spring-context:jar:5.1.1.RELEASE"
)

maven_jar(
name = "org_springframework_spring_aop",
artifact = "org.springframework:spring-aop:jar:5.1.1.RELEASE"
)

maven_jar(
name = "org_springframework_spring_expression",
artifact = "org.springframework:spring-expression:jar:5.1.1.RELEASE"
)

maven_jar(
name = "org_springframework_boot_spring_boot",
artifact = "org.springframework.boot:spring-boot:jar:2.0.6.RELEASE"
)

maven_jar(
name = "org_springframework_boot_spring_boot_autoconfigure",
artifact = "org.springframework.boot:spring-boot-autoconfigure:jar:2.0.6.RELEASE"
)

maven_jar(
name = "org_springframework_boot_spring_boot_starter_aop",
artifact = "org.springframework.boot:spring-boot-starter-aop:jar:2.0.6.RELEASE"
)

maven_jar(
name = "org_springframework_boot_spring_boot_starter_web",
artifact = "org.springframework.boot:spring-boot-starter-web:jar:2.0.6.RELEASE"
)

maven_jar(
name = "org_springframework_boot_spring_boot_starter_test",
artifact = "org.springframework.boot:spring-boot-starter-test:jar:2.0.6.RELEASE"
)

maven_jar(
name = "org_apache_tomcat_embed_tomcat_embed_core",
artifact = "org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.12"
)

maven_jar(
name = "org_apache_tomcat_embed_tomcat_embed_jasper",
artifact = "org.apache.tomcat.embed:tomcat-embed-jasper:jar:9.0.12"
)

maven_jar(
name = "org_springframework_boot",
artifact = "org.springframework.boot:spring-boot-starter-tomcat:jar:2.0.6.RELEASE"
)

maven_jar(
name = "javax_servlet_jstl",
artifact = "javax.servlet:jstl:jar:1.2"
)

maven_jar(
name = "javax_servlet_javax_servlet_api",
artifact = "javax.servlet:javax.servlet-api:jar:4.0.1"
)

maven_jar(
name = "commons_logging_commons_logging",
artifact = "commons-logging:commons-logging:jar:1.2"
)

maven_jar(
name = "javax_servlet_jsp_javax_servlet_jsp_api",
artifact = "javax.servlet.jsp:javax.servlet.jsp-api:jar:2.3.3"
)

和我的构建文件

java_binary(
name = "AbcClient",
srcs = glob(["src/main/java/com/example/abc/*.java"]),
deps = [
"@org_springframework_spring_core//jar",
"@org_springframework_spring_beans//jar",
"@org_springframework_spring_aop//jar",
"@org_springframework_spring_expression//jar",
"@org_springframework_boot_spring_boot//jar",
"@org_springframework_boot_spring_boot_autoconfigure//jar",
"@org_springframework_spring_context//jar",
"@org_springframework_boot_spring_boot_starter_aop//jar",
"@org_springframework_boot_spring_boot_starter_web//jar",
"@org_apache_tomcat_embed_tomcat_embed_core//jar",
"@org_apache_tomcat_embed_tomcat_embed_jasper//jar",
"@javax_servlet_jstl//jar",
"@javax_servlet_javax_servlet_api//jar",
"@javax_servlet_jsp_javax_servlet_jsp_api//jar",
"@commons_logging_commons_logging//jar",
],
resources = glob([
"src/main/java/resources/*",
"src/main/java/webapp/resources/**"
])
)

最佳答案

拥有 spring-boot-starter-web 依赖项就足够了,默认情况下包括 Tomcat。运行应用程序时您可能会缺少依赖项,例如看到 SpringBootServletInitializer 存在并正在运行。

看看bazel-springboot-rule项目和springboot.bzl Packager它使用 Bazel 将 Spring Boot 应用程序打包为可运行的 JAR(与 Maven 和 Gradle 完成的方式类似)。或多或少是这样的:

load("//tools/springboot:springboot.bzl",
"springboot",
"add_boot_web_starter"
)

add_boot_web_starter(app_deps)

springboot(
name = "spring-boot-sample",
boot_app_class = "com.main.Application",
deps = app_deps
)

关于java - 我的 Spring Boot 应用程序加载后立即退出,不会出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53009654/

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