Springboot应用程序立即退出

G. *_*han 0 spring intellij-idea spring-boot

当我运行我的spring boot应用程序时,它会立即(带有exit code 0)退出:

 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.0.RELEASE)

2018-11-27 14:08:31.219  INFO 94920 --- [  restartedMain] c.springbootsecurity.jwt.JwtApplication  : Starting JwtApplication on 1000810002637M.local with PID 94920 (/Users/723305/Documents/spring/springbootSecure/target/classes started by 723305 in /Users/723305/Documents/spring/springbootSecure)
2018-11-27 14:08:31.222  INFO 94920 --- [  restartedMain] c.springbootsecurity.jwt.JwtApplication  : No active profile set, falling back to default profiles: default
2018-11-27 14:08:31.252  INFO 94920 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2018-11-27 14:08:31.722  INFO 94920 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2018-11-27 14:08:31.743  INFO 94920 --- [  restartedMain] c.springbootsecurity.jwt.JwtApplication  : Started JwtApplication in 0.752 seconds (JVM running for 1.294)

Process finished with exit code 0
Run Code Online (Sandbox Code Playgroud)

我的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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.springbootSecurity</groupId>
    <artifactId>jwt</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>jwt</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

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

        </plugins>
    </build>        
</project>
Run Code Online (Sandbox Code Playgroud)

Him*_*ami 7

由于您在pom.xml中进行了春季启动,因此没有将其声明为启动程序Web项目,它会立即关闭,这是预期的行为,现在要作为Web容器运行,您需要在pom.xml中添加以下代码。

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)

  • 我有 spring-boot-started-web 依赖项,但它仍然退出。 (3认同)

avd*_*dyk 6

我刚刚遇到了 IntelliJ 的问题(即使是spring-boot-starter-web),并通过编辑启动器和检查Include dependencies with "Provided" scope选项来解决它。

Web 应用程序在命令行中运行良好。

  • 正如我所写:“与 spring-boot-starter-web 相关的事件”;-) (2认同)
  • 我在 intellij 中遇到了同样的问题,但通过在按所述切换依赖项后右键单击项目 -&gt; maven -&gt; 重新加载项目来修复它 (2认同)

bit*_*ttu 1

我认为这没有任何问题。

Process finished with exit code 0
Run Code Online (Sandbox Code Playgroud)

这表示过程愉快地结束了。

鉴于您的应用程序没有spring-boot-starter-web依赖性,那么它不会启动任何服务器并且不会等待任何请求。

它与 main 方法非常相似,main 方法没有任何要执行的内容,也不会在主代码完成后立即完成。