Why does my Spring Boot App always shutdown immediately after starting?
Resolution: the app is not a webapp because it doesn't have an embedded container (e.g. Tomcat) on the classpath. Adding one fixed it. If you are using Maven, then add this in pom.xml
:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
For Gradle (build.gradle
) it looks like
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web'
}
Spring Boot Application immediately shuts down after starting
Problem is solved - thanks for your help crazycoder.
The issue was caused by an older version of tomcat. After upating the embedded tomcat of Spring to 1.5.3_RELEASE and updating mysql-jdbc-driver as well , it finally worked for me.
I adjusted the pom.xml like this:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent>
spring-boot application shutdown immediately after starting (schedular)
While Spring Boot enables a lot of things depending on your dependencies it doesn't do so for scheduling and async. You still need to manually enable that by adding, respectively, @EnableScheduling
and @EnableAsync
.
In your case adding @EnableScheduling
to your application class is enough.
@SpringBootApplication
@EnableScheduling
public class SpringSchedularApplication {
public static void main(String[] args) {
SpringApplication.run(SpringSchedularApplication.class, args);
}
}
With this scheduling will be enabled and because there is a scheduling thread still running the application won't shutdown.
Why does my Spring Boot application shuts down as soon as I run it?
I think that this is causing trouble and you should remove it
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
You have this one that has the Tomcat
already embedded
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
So a brief overview on why you faced the issue:
You tried to use an external tomcat and specified to your application that you will provide it to it by the runtime <scope>provided</scope>
check it here. But the application already has it embedded in it, and spring-boot by default creates a jar
file, the tomcat
needs a war
file. In addition, the tomcat server won't launch your main method, you need to start your application as a normal spring app.
To use an external tomcat
server follow these steps:
Set the packing to generate
war
<packaging>war</packaging>
Add the external
tomcat
dependency
<dependency>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-starter-tomcat</artifactid>
<scope>provided</scope>
</dependency>
- Exclude the embedded tomcat from the
spring-boot-starter-web
<dependency>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-starter-web</artifactid>
<exclusions>
<exclusion>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-starter-tomcat</artifactid>
</exclusion>
</exclusions>
</dependency>
And make a bunch of configurations to make it start as a Spring app
and add the external configuration of your spring boot app on tomcat.
Check this article here I think it will complete the whole idea. link
Related Topics
The Import Org.Junit Cannot Be Resolved
Converting Date to 08:00:00.000+0000
How to Use Different Jsonproperty on Serialize & Deserialize Using Jackson API
Kafka: Failed to Update Metadata After 60000 Ms
Spring Boot Controller Not Mapping
How to Find Out If String Has Already Been Url Encoded
How to Exclude an Android App from Battery Optimization Using Code
How to Conditionally Enable or Disable Scheduled Jobs in Spring
Dto Pattern: Best Way to Copy Properties Between Two Objects
How to Create Comma Separated String in Single Quotes from Arraylist of String in Java
Regular Expression to Validate Username
Splitting String With Parentheses
Reading Data from Nested Json Object Using Java
Placing a Jlabel At a Specific X,Y Coordinate on a Jpanel
How to Use Limit in Spring Within SQL Query