【问题标题】:Springboot Application exits immediatelySpring Boot 应用程序立即退出
【发布时间】:2019-04-28 18:04:54
【问题描述】:

当我运行 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

我的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>

【问题讨论】:

  • 请添加更多细节。您刚刚发布了很多代码和您的pom,我们不知道情况以及您尝试了什么
  • 所以,我使用 spring 初始化程序创建了一个应用程序并尝试运行它,它显示上述消息。 google 上的大多数帖子都建议删除依赖 tomcat 的 provider ,但我没有
  • 你没有显示你的 main(),或者你自己的任何 bean?里面有你的代码吗?
  • @moilejter 不,我刚刚使用 springinitializer 创建了应用程序,它甚至没有运行。我只有主课。 ` @SpringBootApplication public class JwtApplication { public static void main(String[] args) { SpringApplication.run(JwtApplication.class, args); } }`
  • stackoverflow.com/questions/32758996/… 。我认为这会对你有所帮助。

标签: spring spring-boot intellij-idea


【解决方案1】:

因为你在 pom.xml 中使用 spring boot,你没有声明为 starter web 项目,它会 立即关闭,这是一种预期行为,现在要作为 Web 容器运行,您需要在 pom.xml 中添加以下代码。

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

【讨论】:

  • 我有 spring-boot-started-web 依赖,但它仍然退出。
【解决方案2】:

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

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

【讨论】:

  • 你应该添加&lt;dependency&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt; &lt;/dependency&gt;
  • 正如我所写:“使用 spring-boot-starter-web 的事件”;-)
  • 我在 intellij 中遇到了同样的问题,但是通过右键单击项目 -> maven -> 在按照描述切换依赖项后重新加载项目来修复它
  • 以上工作。我不得不重新导入项目(右键单击项目根文件夹 -> Maven -> 重新导入)。这似乎是一个问题,IntelliJ 可能早期检测为独立桌面项目,后来正确识别为 Web 项目并初始化 Tomcat(绑定到端口并等待连接)。
【解决方案3】:

我认为这没有任何问题。

Process finished with exit code 0

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

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

它非常类似于 main 方法,它没有任何东西要执行或在主代码完成后立即结束。

【讨论】:

  • org.springframework.bootspring-boot-starter-web。即使这样也行不通
  • 好的,你仍然得到相同的日志吗?没有像“tomcat 在端口 8080 上启动”这样的日志?
  • 很奇怪。似乎 web 依赖项没有添加到您的类路径中。您可以重新导入模块的所有依赖项并重新启动应用程序吗?
  • 执行 maven clean install 会重新导入所有依赖
【解决方案4】:

我也遇到了同样的问题。像spring-boot-starter-web 或删除依赖项spring-boot-starter-tomcat 这样的依赖项都不起作用。我使用的是 IntelliJ Idea IDE 社区版。我认为这与 IntelliJ Idea 社区版本有关,因为他们提到社区版本不支持 spring,仅在最终(商业)版本中,至少对于 mac。

https://www.jetbrains.com/idea/download/#section=mac

我之所以这么想,是因为我切换到了 Visual Studio 代码,安装了 Spring Boot 所需的插件,并且它使用我现有的 pom.xml 文件开箱即用。

我目前的依赖是:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

值得一提的是,它也可以在没有 spring-boot-starter-tomcat 依赖的情况下工作。

【讨论】:

  • 需要spring-boot-starter-web
【解决方案5】:

确保您运行 Maven Build 以安装所有依赖项

【讨论】:

    猜你喜欢
    • 2019-06-04
    • 2020-09-22
    • 1970-01-01
    • 2017-01-14
    • 2018-02-04
    • 1970-01-01
    • 1970-01-01
    • 2016-06-26
    • 2012-11-16
    相关资源
    最近更新 更多