java - Spring Boot 应用程序在启动时终止

标签 java spring spring-boot

我正在尝试一个简单的 spring boot 应用程序,它总是自动关闭

 :: Spring Boot ::        (v1.4.1.RELEASE)
2016-10-23 13:05:21.681  INFO 16532 --- [           main] com.example.RestBootApplication          : No active profile set, falling back to default profiles: default
2016-10-23 13:05:21.766  INFO 16532 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@6e20b53a: startup date [Sun Oct 23 13:05:21 EDT 2016]; root of context hierarchy
2016-10-23 13:05:23.682  INFO 16532 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2016-10-23 13:05:23.704  INFO 16532 --- [           main] com.example.RestBootApplication          : Started RestBootApplication in 2.632 seconds (JVM running for 5.168)
2016-10-23 13:05:23.705  INFO 16532 --- [       Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@6e20b53a: startup date [Sun Oct 23 13:05:21 EDT 2016]; root of context hierarchy
2016-10-23 13:05:23.708  INFO 16532 --- [       Thread-2] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown

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.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>rest-boot</name>
    <description>Demo project for Spring Boot</description>

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

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


</project>

主类

@SpringBootApplication
public class RestBootApplication {

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

Controller

@Controller
public class HelloController {

    @RequestMapping("/hello")
    String helloWorld(){
        return "helloWorld";
    }

}

尝试在 spring 工具套件中运行。它总是在启动后停止。在查看了一些 stackoverflow 问题后,我什至添加了“spring-boot-starter-web”,但仍然面临这个问题。

请有人指出这个问题。

最佳答案

在我的例子中,只是将以下内容添加到 pom 文件中

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

关于java - Spring Boot 应用程序在启动时终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40205600/

相关文章:

java - 在制作Android SDK时,有没有一种方法可以不断更新开发人员的值,而无需他们传递 View ?

spring-boot - 来自 docker 的 Consul 共享网络

java - 无法从 START_OBJECT token 中反序列化 `java.lang.String` 的实例

java - Fly.io 上对 Spring Boot 应用程序的云原生 Buildpack 支持 : No buildpack groups passed detection

java - 同步集合 getter

java - 使用其他包中的私有(private)构造函数扩展类

java - 将 XMLGregorianCalendar 转换为 java.sql.Timestamp

Spring Web Controller 在 .html 扩展名下返回 XML

java - Spring MVC - 使用 java 为 Controller 创建 httprequest

java - 使用 JPA 存储库的通配符字段 QueryByExample