【问题标题】:Why springboot application stops immediately from IDEA but works with mvn spring-boot:run为什么 spring boot 应用程序会立即从 IDEA 停止,但可以使用 mvn spring-boot:run
【发布时间】:2022-01-30 19:08:36
【问题描述】:

当我使用命令“mvn spring-boot:run”运行 springboot 应用程序时,它会启动 tomcat 并继续运行,但当从主类“com.example.demo.DemoApplication”从 Intellij 启动时,它会立即关闭相同的应用程序带有以下日志。如何从 IDE 运行它:

 :: Spring Boot ::                (v2.6.3)

2022-01-30 14:02:25.137  INFO 11024 --- [           main] com.example.demo.DemoApplication         : Starting DemoApplication using Java 1.8.0_291 on LAPTOP-1D3EOLKG with PID 11024 (C:\Users\SurajBahl\Downloads\demo\target\classes started by suraj.bahl in C:\Users\SurajBahl\Downloads\demo)
2022-01-30 14:02:25.139  INFO 11024 --- [           main] com.example.demo.DemoApplication         : No active profile set, falling back to default profiles: default
2022-01-30 14:02:25.907  INFO 11024 --- [           main] com.example.demo.DemoApplication         : Started DemoApplication in 1.214 seconds (JVM running for 2.099)

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.6.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>2021.0.0</spring-cloud.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-function-web</artifactId>
            <version>3.0.10.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-function-context</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

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

</project>

【问题讨论】:

    标签: java spring-boot maven intellij-idea


    【解决方案1】:

    前段时间我在使用 IntelliJ 时遇到了同样的问题 - 对我来说,删除了 .idea 和 .iml 文件夹,然后将项目重新导入 IDE 有帮助。

    更多信息here

    【讨论】:

      猜你喜欢
      • 2016-04-10
      • 2014-06-19
      • 1970-01-01
      • 2020-09-27
      • 1970-01-01
      • 2018-04-20
      • 2018-02-04
      • 1970-01-01
      • 2019-04-28
      相关资源
      最近更新 更多