启动后立即启动Spring启动应用程序 [英] Spring boot application shutdown immediate after starting

查看:108
本文介绍了启动后立即启动Spring启动应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个简单的SpringBoot应用程序。当我运行我的spring启动应用程序时,它在启动后立即关闭,下面是控制台日志:

I am trying to build a simple SpringBoot application. When I run my spring boot application it shutdown immediate after starting, below is the console log:

.   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::  (v1.4.1.BUILD-SNAPSHOT)

2016-09-06 18:02:35.152  INFO 22216 --- [           main] com.example.SpringBootDemo1Application   : Starting SpringBootDemo1Application on IN-FMCN882 with PID 22216 (E:\workspace\springBoot\SpringBootDemo1\target\classes started by Rahul.Tyagi in E:\workspace\springBoot\SpringBootDemo1)
2016-09-06 18:02:35.158  INFO 22216 --- [           main] com.example.SpringBootDemo1Application   : No active profile set, falling back to default profiles: default
2016-09-06 18:02:35.244  INFO 22216 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@14dd9eb7: startup date [Tue Sep 06 18:02:35 IST 2016]; root of context hierarchy
2016-09-06 18:02:36.527  INFO 22216 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2016-09-06 18:02:36.546  INFO 22216 --- [           main] com.example.SpringBootDemo1Application   : Started SpringBootDemo1Application in 1.781 seconds (JVM running for 2.376)
2016-09-06 18:02:36.548  INFO 22216 --- [       Thread-1] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@14dd9eb7: startup date [Tue Sep 06 18:02:35 IST 2016]; root of context hierarchy
2016-09-06 18:02:36.550  INFO 22216 --- [       Thread-1] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown

以下是我的代码:

SpringBootDemo1Application.java

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Configuration
@EnableAutoConfiguration
@ComponentScan
@Controller
public class SpringBootDemo1Application {


    @ResponseBody
    @RequestMapping("/")
    public String entry(){
        return "My spring boot application";
    }

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

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>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.1.BUILD-SNAPSHOT</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

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

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

我想让服务器保持运行,以便客户端可以点击它以获得响应。
请建议。

I want to keep the server running so that client can hit it for response. Please Suggest.

推荐答案

我能想到的唯一可能的解释是tomcat嵌入式jar不包含在依赖性/罐。由于您已经定义了spring-boot-starter-web依赖项,因此它应该也可以传递性地提取嵌入式tomcat依赖项。但不知怎的,它被排除在外。

The only possible explanation i can think of is that tomcat embedded jar is not included in the dependencies/jar. Since you have already defined "spring-boot-starter-web" dependency, it should have transitively pulled the embedded tomcat dependencies as well. But somehow it is excluded.

要试试的东西。


  1. 执行 mvn dependency:tree并检查tomcat依赖项是否存在以及compile范围

  2. 将spring boot starter版本更改为1.4.0.RELEASE。

这篇关于启动后立即启动Spring启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆