java - 我的 Spring Boot 应用程序在加载后立即退出且没有错误
问题描述
我正在将 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
)
推荐阅读
- node.js - 如何在错误对象 lb4 中添加自定义参数?
- php - GuzzleHttp Clinet 升级服务器后显示警告错误
- angularjs - 在不同的 ng-app 中具有相同名称的 ng-controller 不起作用
- javascript - 如何在 DataTables 中初始化 div?
- php - MacOs 中的 Docker 非常慢
- php - 我使用邮件功能创建了一个联系表。但是所有的邮件都会变成垃圾邮件。我的代码如下
- lodash - 如何防止 lodash map 创建嵌套对象?
- dart - 这可能是 Dart 错误吗?
- azure-language-understanding - 如何在 LUIS.ai 中分别使用日期和数字?
- php - Eloquent 模型的关系