Spring shutdown immediately after launch

I am trying to create a simple SpringBoot application. When I launch the spring boot application, it immediately exits 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] scaAnnotationConfigApplicationContext : Refreshing org.spring framework.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.spring framework.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 

Below is my code:

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 the server to work so that the client can hit it for a response. Suggest.

+8
java spring spring-boot
source share
10 answers

The only possible explanation I can think of is that the built-in tomcat jar is not included in the / jar dependency. Since you already defined the spring-boot-starter-web dependency, it should also transitively pull out the nested tomcat dependencies. But for some reason this is out of the question.

What you need to try.

  • Run "mvn dependency: tree" and check if tomcat dependencies exist also in the "compilation" area
  • Change the start version of spring boot to 1.4.0.RELEASE.
+9
source share

It worked when I changed the spring boot version as follows:

 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.0.RELEASE</version> </parent> 
+3
source share

Try adding server.port=someAvailablePortNumber to the application.properties file located in the "resources" folder.

I also had the same problem. tried many changes suggested in the pom.xml file but nothing worked for me. In my case, port 8080 was not available, so the application could not start tomcat using the default port (i.e.: 8080), as a result of which it immediately disconnected.

Changing the port number helped launch tomcat, and the application began to work. Hope this helps :)

+3
source share

If we are not using the .RELEASE spring version, we need to add below repositories to our pom.xml file.

And we can use the command "mvn spring-boot: run" to launch our spring application from the command line.

 <!-- (you don't need this if you are using a .RELEASE version) --> <repositories> <repository> <id>spring-snapshots</id> <url>http://repo.spring.io/snapshot</url> <snapshots><enabled>true</enabled></snapshots> </repository> <repository> <id>spring-milestones</id> <url>http://repo.spring.io/milestone</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>spring-snapshots</id> <url>http://repo.spring.io/snapshot</url> </pluginRepository> <pluginRepository> <id>spring-milestones</id> <url>http://repo.spring.io/milestone</url> </pluginRepository> </pluginRepositories> 
0
source share

For me, this helped update the "parent" link in pom.xml.

this is my working pom.xml:

 <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.boot</groupId> <artifactId>project-boot</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.1.RELEASE</version> </parent> <name>project-boot</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> 

0
source share

In your main function, "SpringApplication.run (Main.class, args.close ()); should not be close, it should be like" SpringApplication.run (Main.class, args); "

Example:

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

Check the log configuration, maybe you are trying to save the logs in a folder that cannot be created.

 <appender name="allFileAppender" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>/var/log/app/all.log</file> ... </appender> 
0
source share

I ran into the same problem, my OS is win7, my idea is eclipse, after I changed the spring boot version to 1.5.7. please, everything is in order.

 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.7.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> 

I tried spring boot 2.0.2.release, 1.5.13.release, 1.5.1.release, they all cannot work on my win7 OS using eclipse, but they can run my ubuntu16.04 using the command line and compile mvn with the same code

0
source share

Cleaning up my local Maven repository solved this problem for me. The easiest way is to remove ~/.m2/repository

0
source share

removed spring-boot-starter-tomcat dependency and it worked.

0
source share

All Articles