启动后立即启动Spring启动应用程序

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

. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: 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] scaAnnotationConfigApplicationContext : 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] osjeaAnnotationMBeanExporter : 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] scaAnnotationConfigApplicationContext : 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] osjeaAnnotationMBeanExporter : 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

   4.0.0 com.example demo 0.0.1-SNAPSHOT jar  org.springframework.boot spring-boot-starter-parent 1.4.1.BUILD-SNAPSHOT      org.springframework.boot spring-boot-starter-web      org.springframework.boot spring-boot-maven-plugin     

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

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

要尝试的东西。

  1. 执行“mvn dependency:tree”并检查tomcat依赖项是否存在以及“compile”范围
  2. 将spring boot starter版本更改为1.4.0.RELEASE。

当我改变弹簧启动版本时,它工作如下:

  org.springframework.boot spring-boot-starter-parent 1.4.0.RELEASE  

尝试在位于“resources”文件夹中的application.properties文件中添加server.port=someAvailablePortNumber

我也遇到了同样的问题。 尝试了pom.xml文件中建议的很多更改,但没有任何对我有用。 在我的情况下,端口8080不可用,因此应用程序无法使用默认端口(即:8080)启动tomcat,导致它立即关闭。

更改端口号有助于启动tomcat并且应用程序开始工作。 希望能帮助到你 :)

如果我们不使用.RELEASE版本的spring,我们需要在pom.xml文件中添加以下存储库。

我们可以使用命令“mvn spring-boot:run”从命令行运行我们的spring应用程序。

    spring-snapshots http://repo.spring.io/snapshot true   spring-milestones http://repo.spring.io/milestone     spring-snapshots http://repo.spring.io/snapshot   spring-milestones http://repo.spring.io/milestone   

为我解决的是更新pom.xml中的“父”引用。

这是我的工作pom.xml:

  4.0.0 com.boot project-boot 0.0.1-SNAPSHOT jar  org.springframework.boot spring-boot-starter-parent 1.5.1.RELEASE  project-boot http://maven.apache.org  UTF-8    org.springframework.boot spring-boot-starter-web   

在您的主函数“SpringApplication.run(Main.class,args.close());”中 不应该接近,它应该像“SpringApplication.run(Main.class,args);”

示例:

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

检查您的日志配置,也许您正在尝试将日志保存到无法创建的文件夹中。

  /var/log/app/all.log ...  

我遇到了同样的问题,我的操作系统是win7,我的ide是eclipse,之后我将spring boot版本更改为1.5.7.release,一切都好。

  org.springframework.boot spring-boot-starter-parent 1.5.7.RELEASE     org.springframework.boot spring-boot-starter-web  

我试过spring boot 2.0.2.release,1.5.13.release,1.5.1.release,他们都不能使用eclipse在我的win7操作系统上运行,但他们可以使用命令行运行我的ubuntu16.04并使用mvn编译相同的代码。

清除我当地的Maven仓库为我解决了这个问题。 最简单的方法是删除~/.m2/repository