Sprint-boot在启动服务器后自动关闭

时间:2018-03-26 22:42:47

标签: java eclipse spring-boot

我正在尝试为练习创建一个简单的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

3 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:1)

确保pom.xml中的spring-boot-starter和spring-boot-web版本兼容

答案 2 :(得分:0)

只需运行mvn clean installmvn spring-boot:run,看看控制台上是否有任何堆栈跟踪可以帮助查找原因..另外验证pom.xml build config为

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