【发布时间】: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