gpt4 book ai didi

java - Spring-boot启动服务器后自动关闭

转载 作者:行者123 更新时间:2023-12-01 17:51:36 36 4
gpt4 key购买 nike

我正在尝试创建一个简单的 Spring-boot 应用程序以供练习。然而,服务器似乎启动但随后立即关闭。这个问题已经持续了好几天了,我不知道如何解决。

我在下面显示了整个控制台输出。当我检查 localhost:8080 时,它什么也没显示。

HelloSpringApplication.java

@SpringBootApplication
public class HelloSpringApplication {

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

pom.xml

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.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-web</artifactId>
</dependency>

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

控制台

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

2018-03-26 17:34:20.469 INFO 5561 --- [ main] com.example.demo.HelloSpringApplication : Starting HelloSpringApplication on Aarons-MacBook-Pro.local with PID 5561 (/Users/aaron/Documents/workspace-sts-3.9.3.RELEASE/HelloSpringApplication/target/classes started by aaron in /Users/aaron/Documents/workspace-sts-3.9.3.RELEASE/HelloSpringApplication)
2018-03-26 17:34:20.472 INFO 5561 --- [ main] com.example.demo.HelloSpringApplication : No active profile set, falling back to default profiles: default
2018-03-26 17:34:20.512 INFO 5561 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@691a7f8f: startup date [Mon Mar 26 17:34:20 CDT 2018]; root of context hierarchy
2018-03-26 17:34:21.021 INFO 5561 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-03-26 17:34:21.030 INFO 5561 --- [ main] com.example.demo.HelloSpringApplication : Started HelloSpringApplication in 0.743 seconds (JVM running for 1.141)
2018-03-26 17:34:21.032 INFO 5561 --- [ Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@691a7f8f: startup date [Mon Mar 26 17:34:20 CDT 2018]; root of context hierarchy
2018-03-26 17:34:21.034 INFO 5561 --- [ Thread-2] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown

最佳答案

该输出看起来类似于使用 spring-boot-starter 而不是 spring-boot-starter-web 的输出,后者具有嵌入式 tomcat 服务器。确保您在当前的 pom.xml 中使用该依赖项。然后使用 mvn clean install 确保依赖项已正确安装,然后使用 mvn spring-boot:run 运行 spring 应用程序。

你可以用start.spring.io初始化一个spring项目,这将提供一个带有预配置空项目的 zip,不要忘记选择 Web 依赖项。

关于java - Spring-boot启动服务器后自动关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49501780/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com