首页 > 解决方案 > Spring Boot 应用程序未启动,也不例外

问题描述

我正在使用 Spring Boot 版本:2.3.5.RELEASE,只有我试图启动的主类。当我运行主类时,我收到以下消息并且应用程序无法启动而没有任何错误。

2020-11-03 12:39:17.871  INFO 15426 --- [           main] com.rahul.poc.HealthcheckApplication     : Starting HealthcheckApplication on INMLTCU6LVCG with PID 15426 (/Users/rahul/Documents/Rahul/Projects/healthcheck/target/classes started by rahul in /Users/rahul/Documents/Rahul/Projects/healthcheck)
2020-11-03 12:39:17.873  INFO 15426 --- [           main] com.rahul.poc.HealthcheckApplication     : No active profile set, falling back to default profiles: default
2020-11-03 12:39:18.617  INFO 15426 --- [           main] com.rahul.poc.HealthcheckApplication     : Started HealthcheckApplication in 1.353 seconds (JVM running for 1.806)

Process finished with exit code 0

pom.xml 如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.rahul.poc</groupId>
    <artifactId>healthcheck</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Healthcheck</name>
    <description>Healthcheck POC</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
<!--            <scope>test</scope>-->
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

主要类为:

package com.rahul.poc;

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

@SpringBootApplication
public class HealthcheckApplication {

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

}

我没有任何其他类或配置。

标签: springspring-boot

解决方案


我相信您的问题是您没有添加一个启动程序包引用,该引用将服务器组件添加到您的应用程序,或者添加任何保持活动状态并执行任何操作的内容。我认为您的应用程序正在运行,然后退出,因为它尚未配置为持续运行任何内容。

导致应用程序保持运行的最常见的缺失是 Web 启动器。将此添加为 Maven 依赖项,您应该会获得更像您期望的行为:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
</dependency>

推荐阅读