Spring boot stops after starting
Although an answer has been accepted, still this might help:
Are you trying to run the application from Intellij from Run menu or by right click and run on the class where your main is defined and you are getting above issue and the application works fine from command line?
If above is the case, I see your pom.xml have dependency with provided scope.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
When running the application from run menu in intellij, dependencies with provided scope are not available by default.
To fix this,
Go to Run Menu -> Edit Configuations and then select Include dependencies with provided scope
Image for reference:
And try to run again. This should fix the issue.
Good luck.
Edit - In newer versions of Intellij, This option is hidden in Modify Options in Run configuration.
Image for reference
I don't see anything glaringly wrong with what you have. I have an app that I deploy both as a jar and war simultaneously in different environments (they differ only by packaging); I have a ServletInitializer
equivalent to yours and it works without issue with one primary difference.
I use a maven run configuration with spring-boot:run
as the "Command line" value. With that I can do no more than change the pom to reflect jar or war, run, and go. I've faced problems when switching back and forth and using a config that invokes main
in the app class. For example, just for fun I just ran an instance of the app with jar packaging and running main
. Wouldn't even launch. This is just after having it jar packaged and launched using the maven config I mentioned above.
I would recommend starting with creating that maven run configuration and see what the results are. Here's the way to do it in Intellij so you don't have to use the command line interface.
- Choose "Edit configurations..." from the dropdown next to the play button.
- Press the green
+
in the upper left-hand corner. - Choose to create a maven configuration.
- Name it.
- Add
spring-boot:run
to the "Command line" entry. - Optionally, make it "Share"d or "Single instance only".
I'm not an eclipse/sts user but I'm sure there's a similar way to do it.