【问题标题】:Spring Boot App shutdown immediately under spring-boot-starter-parent version 2.0.1.RELEASEspring-boot-starter-parent 2.0.1.RELEASE下Spring Boot App立即关闭
【发布时间】:2018-09-26 07:12:20
【问题描述】:

我在学习 JavaBrain 的 spring boot 视频时遇到了与以下链接相同的错误。

Why does my Spring Boot App always shutdown immediately after starting?

我已经指定了spring-boot-starter-web的依赖,但是还是报错。我的 pom.xml 看起来像这样。问题是当我将 spring-boot-starter-parent 的版本更改为 1.4.2.RELEASE 时一切正常(我可以访问 localhost:8080)。我想知道为什么会发生这种情况,我该怎么做才能使 2.0.1.RELEASE 版本正常工作。

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.1.RELEASE</version>
  </parent>

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

代码如下所示:

@SpringBootApplication
public class CourseApiApp {

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

    }

}

输出:

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

2018-04-16 21:42:07.576  INFO 8976 --- [           main] org.kouchibin.web.CourseApiApp           : Starting CourseApiApp on SAI with PID 8976 (C:\Users\86660\Documents\workspace-sts\course-api\target\classes started by kcb in C:\Users\86660\Documents\workspace-sts\course-api)
2018-04-16 21:42:07.583  INFO 8976 --- [           main] org.kouchibin.web.CourseApiApp           : No active profile set, falling back to default profiles: default
2018-04-16 21:42:07.670  INFO 8976 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@4c40b76e: startup date [Mon Apr 16 21:42:07 CST 2018]; root of context hierarchy
2018-04-16 21:42:08.971  INFO 8976 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-04-16 21:42:08.990  INFO 8976 --- [           main] org.kouchibin.web.CourseApiApp           : Started CourseApiApp in 1.976 seconds (JVM running for 2.624)
2018-04-16 21:42:08.997  INFO 8976 --- [       Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@4c40b76e: startup date [Mon Apr 16 21:42:07 CST 2018]; root of context hierarchy
2018-04-16 21:42:09.000  INFO 8976 --- [       Thread-2] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown

【问题讨论】:

  • 如果有异常堆栈跟踪,请您发布
  • 只是配置错误或未正确加载 Web 依赖项。只需从https://start.spring.io/ 创建一个新项目。这将工作 100%
  • @ElarbiMohamedAymen 当然可以。我已经编辑了原始帖子。
  • @Patrick 不。也不工作。我使用 STS 导入下载的项目。相同的输出。不知道我哪里做错了。
  • 您是否构建项目并确保 maven 下载所有依赖项。再次检查你的 pom 中是否有网络

标签: java spring spring-boot


【解决方案1】:

我已经解决了这个问题。当我手动使用mvn compile 时,不是在eclipse 中单击RUN 按钮,而是显示了更多详细信息,其中一些依赖项无法解决。所以我在本地存储库中检查了这些依赖项。问题是某些依赖项没有完全下载(带有“.inprogress”后缀)。所以解决这个问题的方法是删除所有损坏的依赖项并重新编译应用程序,这将再次下载依赖项。我猜这个问题很可能发生在中国,因为防火墙的原因,与 maven 存储库的连接不稳定。而 1.4.2.RELEASE 之所以起作用,仅仅是因为所有依赖项都是偶然成功下载的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-15
    • 2020-06-02
    • 1970-01-01
    • 2022-07-30
    • 1970-01-01
    • 2014-04-07
    • 2020-05-23
    • 2018-10-15
    相关资源
    最近更新 更多