I am new to Spring/Maven, and am following this tutorial: Serving Web Content with Spring MVC.
Everytime I run mvn spring-boot:run
, I get this error:
I made the following changes to make mvn clean spring-boot:run
work:
pom.xml
to the root directory, which makes the directory hierarchy to be:Directory hierarchy:
.
├── pom.xml
└── src
└── main
├── java
│ └── hello
│ ├── Application.java
│ └── GreetingController.java
└── resources
└── templates
└── greeting.html
extensions
in the following part:Commented out part:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!-- Exclusions to allow SpringBoot execute on HCP -->
<!--<exclusions>-->
<!--<exclusion>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-tomcat</artifactId>-->
<!--</exclusion>-->
<!--<exclusion>-->
<!--<groupId>org.apache.tomcat.embed</groupId>-->
<!--<artifactId>tomcat-embed-el</artifactId>-->
<!--</exclusion>-->
<!--<exclusion>-->
<!--<artifactId>logback-classic</artifactId>-->
<!--<groupId>ch.qos.logback</groupId>-->
<!--</exclusion>-->
<!--</exclusions>-->
</dependency>
It seems you meant to exclude those dependencies. mvn clean spring-boot:run
will just exit successfully if the embed tomcat is excluded, but I think this is the correct behave because there's no container to deploy the application. Anyway, you can try it out and make changes according your requirements.
I've same error as yours and finally I found it was cased by the wrong cooperation version between "spring-boot-starter-parent" and "spring-boot-autoconfigure", thereof making sure with same version. And also check their versions are the newest nor not.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>2.1.5.RELEASE</version>
</dependency>
In my case I just delete "tomcat-embed-el" dependency.
<exclusion>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-el</artifactId>
</exclusion>
And it works.....
In my case I just delete "devtools" dependency.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
And it works!
Sometimes the port might just be already in use, make sure you kill all java processes before running an application.