我的Spring Boot应用程序加载后立即退出,没有错误

时间:2018-10-26 13:18:02

标签: java spring spring-boot bazel

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

我认为这与无法找到servlet的spring有关,但是我对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);
    }
}

我的WORKSPACE文件

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"
)

和我的BUILD文件

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/**"
    ])
)

1 个答案:

答案 0 :(得分:1)

具有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
)