254

This is my first Spring Boot code. Unfortunately, it always shuts down. I was expecting it to run continuously so that my web client can get some data from the browser.

package hello;
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;

@Controller
@EnableAutoConfiguration
public class SampleController {

    @RequestMapping("/")
    @ResponseBody
    String home() {
        return "Hello World!";
    }

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


[@localhost initial]$ java -jar build/libs/gs-spring-boot-0.1.0.jar

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::            (v1.0.0.RC4)

2014-03-13 09:20:24.805  INFO 14650 --- [           main] hello.SampleController                   : Starting SampleController on localhost.localdomain with PID 14650 (/home/xxx/dev/gs-spring-boot/initial/build/libs/gs-spring-boot-0.1.0.jar started by xxx)
2014-03-13 09:20:25.002  INFO 14650 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@b9eec: startup date [Thu Mar 13 09:20:24 EDT 2014]; root of context hierarchy
2014-03-13 09:20:28.833  INFO 14650 --- [           main] o.s.b.a.e.jmx.EndpointMBeanExporter      : Registering beans for JMX exposure on startup
2014-03-13 09:20:30.148  INFO 14650 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 0
2014-03-13 09:20:30.154  INFO 14650 --- [           main] o.s.b.a.e.jmx.EndpointMBeanExporter      : Located managed bean 'requestMappingEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=requestMappingEndpoint]
2014-03-13 09:20:30.316  INFO 14650 --- [           main] o.s.b.a.e.jmx.EndpointMBeanExporter      : Located managed bean 'environmentEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=environmentEndpoint]
2014-03-13 09:20:30.335  INFO 14650 --- [           main] o.s.b.a.e.jmx.EndpointMBeanExporter      : Located managed bean 'healthEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=healthEndpoint]
2014-03-13 09:20:30.351  INFO 14650 --- [           main] o.s.b.a.e.jmx.EndpointMBeanExporter      : Located managed bean 'beansEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=beansEndpoint]
2014-03-13 09:20:30.376  INFO 14650 --- [           main] o.s.b.a.e.jmx.EndpointMBeanExporter      : Located managed bean 'infoEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=infoEndpoint]
2014-03-13 09:20:30.400  INFO 14650 --- [           main] o.s.b.a.e.jmx.EndpointMBeanExporter      : Located managed bean 'metricsEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=metricsEndpoint]
2014-03-13 09:20:30.413  INFO 14650 --- [           main] o.s.b.a.e.jmx.EndpointMBeanExporter      : Located managed bean 'traceEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=traceEndpoint]
2014-03-13 09:20:30.428  INFO 14650 --- [           main] o.s.b.a.e.jmx.EndpointMBeanExporter      : Located managed bean 'dumpEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=dumpEndpoint]
2014-03-13 09:20:30.450  INFO 14650 --- [           main] o.s.b.a.e.jmx.EndpointMBeanExporter      : Located managed bean 'autoConfigurationAuditEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=autoConfigurationAuditEndpoint]
2014-03-13 09:20:30.465  INFO 14650 --- [           main] o.s.b.a.e.jmx.EndpointMBeanExporter      : Located managed bean 'shutdownEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=shutdownEndpoint]
2014-03-13 09:20:30.548  INFO 14650 --- [           main] o.s.b.a.e.jmx.EndpointMBeanExporter      : Located managed bean 'configurationPropertiesReportEndpoint': registering with JMX server as MBean [org.springframework.boot:type=Endpoint,name=configurationPropertiesReportEndpoint]
2014-03-13 09:20:30.589  INFO 14650 --- [           main] hello.SampleController                   : Started SampleController in 7.396 seconds (JVM running for 9.569)
2014-03-13 09:20:30.608  INFO 14650 --- [       Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@b9eec: startup date [Thu Mar 13 09:20:24 EDT 2014]; root of context hierarchy
2014-03-13 09:20:30.610  INFO 14650 --- [       Thread-2] o.s.c.support.DefaultLifecycleProcessor  : Stopping beans in phase 0
2014-03-13 09:20:30.624  INFO 14650 --- [       Thread-2] o.s.b.a.e.jmx.EndpointMBeanExporter      : Unregistering JMX-exposed beans on shutdown

Please advise.

Thanks

P.S. build.gradle is the fault.

dependencies {
    // tag::jetty[]
    compile("org.springframework.boot:spring-boot-starter-web") {
        **exclude module: "spring-boot-starter-tomcat"**
    }

Once I took off the above line in bold, everything works. My application context now is correct. Thanks Dave

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::            (v1.0.0.RC4)

2014-03-13 13:58:08.965  INFO 7307 --- [           main] hello.Application                        : Starting
 Application on  with PID 7307 (/ladev/home/xxx/dev/gs-spring-boot/initial/build/libs/gs-spring-boo
t-0.1.0.jar started by xxx)
2014-03-13 13:58:09.021  INFO 7307 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshi
ng org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@45490eb5: startup
 date [Thu Mar 13 13:58:09 MDT 2014]; root of context hierarchy
2014-03-13 13:58:09.653  INFO 7307 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overridi
ng bean definition for bean 'beanNameViewResolver': replacing [Root bean: class [null]; scope=; abstract=fal
se; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanNam
e=org.springframework.boot.actuate.autoconfigure.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration;
 factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class
 path resource [org/springframework/boot/actuate/autoconfigure/ErrorMvcAutoConfiguration$WhitelabelErrorView
Configuration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3;
 dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconf
igure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter; factoryMethodName=beanNameViewResolver; in
itMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/au
toconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
Adam
  • 5,215
  • 5
  • 51
  • 90
johnsam
  • 4,192
  • 8
  • 39
  • 58
  • Are you using Maven or Gradle ? – Romain Moreau Mar 13 '14 at 14:22
  • 1
    Your `ApplicationContext` is the wrong type (`AnnotationConfigApplicationContext`), so it's not a webapp. It should default to a value that depends on your classpath, so it looks like that is being set or defaulted the wrong way. Maybe you have an `application.properties` or an ENV var your are not showing? – Dave Syer Mar 13 '14 at 15:16
  • You are right. My ApplicationContext is incorrect. I don't have an application.properties file. How do I make it run the right ApplicationContext? Maybe a web ApplicationContext? – johnsam Mar 13 '14 at 15:38
  • Let's try and simplify the build. Can you remove all dependencies except spring-boot-starter-web, and then run with `--debug` on the command line and post the logs back here, please? – Dave Syer Mar 13 '14 at 15:56
  • Dave, I updated my original post since the responses were too long. – johnsam Mar 13 '14 at 16:05
  • It's not really telling us anything new (except that Jetty isn't the problem). Can you double check your environment (`env | grep -i spring` for instance)? And the output from `--debug` would really help so if you can paste it somewhere that would be great. – Dave Syer Mar 13 '14 at 16:18
  • Dave, env | grep -i spring OLDPWD=/u/xxx/dev/gs-spring-boot PWD=/u/xxx/dev/gs-spring-boot/initial java -jar --debug build/libs/gs-spring-boot-0.1.0.jar Unrecognized option: --debug Could not create the Java virtual machine. – johnsam Mar 13 '14 at 19:28
  • Dave it is working now. There was a bad line in build.gradle. I've updated my original post. – johnsam Mar 13 '14 at 20:06
  • my spring boot app , has that dependency , but still is restarting , is their any other i need to check , can you please help me – Bravo Jan 29 '18 at 13:06

23 Answers23

514

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'
}
Andrew Tobilko
  • 48,120
  • 14
  • 91
  • 142
Dave Syer
  • 56,583
  • 10
  • 155
  • 143
  • 11
    I have a simple java application then why we need to add this dependency? – AMAN KUMAR Jun 20 '17 at 13:40
  • 4
    Please mention that this dependency needs to be the first one. – Cosmin Oprea Mar 29 '18 at 11:20
  • It doesn’t though. Just on the classpath. – Dave Syer Mar 29 '18 at 14:20
  • 1
    For gradle ,i had used that dependencies but it's not working. – Sagar Gangwal May 28 '18 at 07:35
  • This property is only working in linux not in windows. – Kanav Narula Sep 18 '18 at 14:10
  • I already have that and it's still shutting down when running in a container on kubernetes. – emirhosseini Dec 07 '18 at 20:25
  • 1
    My application had the embedded container as stated above AND spring-boot-starter-tomcat which was all generated by springinitialzr. All I had to do was remove provided from the "tomcat one". Why are there two dependences for tomcat in my pom?! – chrips Jan 12 '19 at 09:17
  • 1
    This solved my problem as well. But I am a bit confused that why would we always need spring-boot-starter-web in order to successfully start spring boot app. – old_soul_on_the_run Nov 20 '19 at 05:16
  • 1
    You don't (need the starter). The app started successfully before you did that. It also exited successfully. If you don't want it to exit you have to keep it busy, and starting a web server is one way to do that. – Dave Syer Nov 20 '19 at 16:28
  • adding below dependency works for me: org.springframework.boot spring-boot-starter-web Regards, Rasool Javeed Mohammad – M R Javeed May 22 '20 at 15:30
  • 2
    for me compile didn't work, but when I changed to implementation it didn't run in "java -jar xyz.jar" in command line. Any idea? – Satish Patro May 30 '20 at 11:39
  • @DaveSyer - Disagree. My code is full of annotations like `@RestController` and `@PostMapping`. It compiled those fine, so at some level it was understood that this is supposed to be a web app. It should have logged literally anything to convey that a dependency was missing keeping this from being the web app it's supposed to be. – ArtOfWarfare Aug 18 '23 at 19:03
49

I had the same problem but when I removed the below dependency it worked fine

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>

it started working again.

N. berouain
  • 1,181
  • 13
  • 17
  • 3
    @georgiana_e My application started working after I removed tomcat dependency :D What's going on?? – Frankie Drake Oct 29 '17 at 19:44
  • I replaced my [default Embedded Container with Jetty](https://www.mkyong.com/spring-boot/spring-boot-jetty-as-embedded-server/) to fix the error. Seems like my Tomcat JARs were broken, and an .m2 purge was needed. – CᴴᴀZ Apr 16 '18 at 14:22
  • it worked for me, but why? – Rafael Andrade Jul 12 '22 at 03:22
  • remove `spring.main.web-application-type=none` from application.properties as well if didn't work. – DragonKnight Aug 09 '22 at 02:40
  • It's possible that you were using the spring-boot-starter-tomcat dependency to include an embedded Tomcat server in your Spring Boot application. When you removed this dependency, you also removed the embedded Tomcat server, which could explain why the server is no longer shutting down properly. I guess you understand now – Salami Korede Jan 05 '23 at 06:09
36

Here is how you can fix it:

  1. Check if you don't have dependency on spring-boot-starter-web in your pom.xml file. To get you pom.xml file right, use this link start.spring.io

  2. If you have above dependency, but still facing the issue, it is highly possible that your embedded tomcat jars are present. To confirm this, run maven build in debug mode -

mvn spring-boot:run --debug

and look for messages like -

[WARNING] error reading /Users/sparrowmac1/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.5.20/tomcat-embed-core-8.5.20.jar; invalid LOC header (bad signature) [WARNING] error reading /Users/sparrowmac1/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.8.10/jackson-core-2.8.10.jar; invalid LOC header (bad signature)

If such messages are present, purge your local maven repo and try again -

mvn dependency:purge-local-repository

chatsap
  • 631
  • 6
  • 5
10

My application is Spring boot batch and commenting below line in application.properties resolved the problem

spring.main.web-application-type=none
Prashant S
  • 349
  • 4
  • 14
  • Yup, this fixed my problem although I had the spring-boot-starter-web dependency I was wondering why it was being terminated and figured I had the spring.main.web-application-type=none property in application.properties – Vikram Palakurthi Jun 17 '21 at 16:28
8

Maybe it does not fit to your code but i found out if you have a code snippet like this:

@SpringBootApplication
public class SpringBootApacheKafkaApplication {

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

then just remove the close() method. That's fixed my problem! Maybe I can help someone with that

Guchelkaben
  • 1,205
  • 1
  • 12
  • 18
7

I initialized a new SPring boot project in IntelliJIdea with Spring Boot dev tools, but in pom.xml I had only dependency

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

You need to have also artifact spring-boot-starter-web. Just add this dependency to pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
Hourglasser
  • 667
  • 1
  • 9
  • 17
6

In my case the problem was introduced when I fixed a static analysis error that the return value of a method was not used.

Old working code in my Application.java was:

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

New code that introduced the problem was:

    public static void main(String[] args) {        
      try (ConfigurableApplicationContext context = 
          SpringApplication.run(Application.class, args)) {
        LOG.trace("context: " + context);
      }
    }

Obviously, the try with resource block will close the context after starting the application which will result in the application exiting with status 0. This was a case where the resource leak error reported by snarqube static analysis should be ignored.

Farrukh Najmi
  • 5,055
  • 3
  • 35
  • 54
6

Using gradle, I just replaced this line at build.gradle.kts file in dependencies block

providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")

to this

compile("org.springframework.boot:spring-boot-starter-web")

and it worked fine.

Pedro Muniz
  • 568
  • 12
  • 19
3

I think the right answer was at Why does Spring Boot web app close immediately after starting? about the starter-tomcat not being set and if set and running through the IDE, the provided scope should be commented off. Scope doesn't create an issue while running through command. I wonder why.

Anyways just added my additional thoughts.

Community
  • 1
  • 1
Ajay Menon
  • 127
  • 6
3

Just another possibility,

I replaced

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

with

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

and it started without any issues

Mohammed Rafeeq
  • 2,586
  • 25
  • 26
2

If you don't want to make your spring a web application then just add @EnableAsync or @EnableScheduling to your Starter

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

}
deFreitas
  • 4,196
  • 2
  • 33
  • 43
1

this work with spring boot 2.0.0

replace

  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
        </dependency>

with

<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>9.0.6</version>
    </dependency>
RAUL
  • 104
  • 1
  • 3
1

In my case I fixed this issue like below:-

  1. First I removed (apache) C:\Users\myuserId\.m2\repository\org\apache

  2. I added below dependencies in my pom.xml file

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    
  3. I have changed the default socket by adding below lines in resource file ..\yourprojectfolder\src\main\resourcesand\application.properties(I manually created this file)

     server.port=8099
     spring.profiles.active=@spring.profiles.active@
    

    for that I have added below block in my pom.xml under <build> section.

      <build>
      .
      .
     <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
       .
       .    
      </build>
    

My final pom.xml file look like

<?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.bhaiti</groupId>
    <artifactId>spring-boot-rest</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>spring-boot-rest</name>
    <description>Welcome project for Spring Boot</description>

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

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>

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

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

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>

    </build>


</project>
Abhijit Pritam Dutta
  • 5,521
  • 2
  • 11
  • 17
1

I went through the answers here and elsewhere and still had issues. It turned that (like the op), I was running in kubernetes, and the app was fine, but kubernetes had an issue.

I forgot to have my app start based on my port environment variable. So, kubernetes/helm was telling it to run on 8443 and to liveness probe that, but it was running on some other port (like 8123) from my application.properties.

The kubernetes events (get events) showed the live-ness probe was failing, so kubernetes was killing the pod/app every 30 seconds or so.

John Humphreys
  • 37,047
  • 37
  • 155
  • 255
1

If you have a circular spring injected dependency it will fail without warning, depending on the level of logging, and a few other factors.

Class A injects Class B, and Class B injects Class A. Via constructor, in this particular case.

  • Basic problem is due to missing dependency as per accepted answer. Still the issue persist means, Michael's recommendation to be checked. For my case, log4j dependency has cyclic dependency and hence boot is getting stopped immediately without logging any details. After correcting log4j dependency, got the actual reason for failure.Thanks Michael for the hint. – Krishna Dec 18 '20 at 13:54
1

I had this problem, and in my case it was caused by a simple clumsy mistake: my class had:

@SpringBootApplication
public class MyApplication implements ApplicationRunner {

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

public void run(ApplicationArguments args) throws Exception {

}

}

I removed the "implements ApplicationRunner" and the run method (which were there due to a copy-paste mistake) and then it worked

MJL
  • 352
  • 3
  • 11
1

If you are using Java 9 JPMS it is not enough to add spring-boot-starter-web as a dependency, as tomcat-embed lib would not be available at runtime and spring boot will not detect the app as web app.

To fix this make tomcat embed available via following directive added to your module-info.java for main app

 requires org.apache.tomcat.embed.core;
 
walkeros
  • 4,736
  • 4
  • 35
  • 47
1

In my case, the problem happened when I tried to insert 5000 records into database (it worked okay with fewer records)
What worked for me: Uncomment devtools dependency in pom.xml file:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <optional>true</optional>
</dependency>
emsnguyen
  • 41
  • 7
1

if you want to see detail logs then you can run it with debug on using below command

 java  -Ddebug -jar .\app.jar

For me it was due to below exception

 org.apache.logging.log4j.core.appender.AppenderLoggingException: java.lang.NoSuchMethodError: org.apache.logging.log4j.util.StackLocatorUtil.getCurrentStackTrace()Ljava/ut
Dhiraj Surve
  • 310
  • 2
  • 5
0

in my case i already had the maven dependency to 'spring-boot-starter-web' and the project would start fine without auto-stopping when i run it as springboot app from within the IDE. however, when i deploy it to K8s, the app would start and auto-stop immediately. So i modified my main app class to extend SpringBootServletInitializer and this seems to have fixed the auto-stopping.

@SpringBootApplication public class MyApp extends SpringBootServletInitializer {  public static void main(String[] args) {
SpringApplication.run(MyApp.class, args);  }}
abdel
  • 643
  • 1
  • 5
  • 13
0

I was having a similar problem. I only had the following starter web package.

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

But it is not enough. You need to add a parent too to get other required dependencies.

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.4.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
Erangad
  • 671
  • 7
  • 16
0

Here is how you can fix it:

Check if you don't have dependency on spring-boot-starter-web in your pom.xml file. To get you pom.xml file right, use this link start.spring.io

If you have above dependency, but still facing the issue, it is highly possible that your embedded tomcat jars are present. To confirm this, run maven build in debug mode -

mvn spring-boot:run --debug
Joel Wembo
  • 814
  • 6
  • 10
0

Removing this dependency worked for me

    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-core</artifactId>
        <version>9.0.73</version>
    </dependency> 
Amos Machora
  • 486
  • 3
  • 12