Exception and code: SpringCloud project startup error: WebServerException: Unable to start embedded Tomcat

Caused by: org.springframework.boot.web.server.WebServerException: 
Unable to start embedded Tomcat at org.springframework.boot.web.embedded.tomcat.
TomcatWebServer.initialize(TomcatWebServer.java:142) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]Copy the code

Cause analysis:

First look at the SpringCloud project configuration file, the parent module’s POM.xml and the program’s startup class’s annotation configuration. After eliminating syntax errors caused by bugs, you need to check the configuration of the pair dependencies in the pom.xml file.

  • The original configuration is as follows: We can see that SpringBoot is 2.3.0 and SpringCloud is Greenwich. After checking the data, it is found that the SpringCloud project and SpringBoot have a relatively strict version match. You can no longer change the version of SpringBoot at any time as you do when developing individual applications.

      <! SpringBoot -->
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.3.0. RELEASE</version>
            <relativePath/>
        </parent>
        <properties>        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <java.version>1.8</java.version>
            <! -- Spring Cloud version -->
            <! --<spring-cloud.version>Hoxton.SR6</spring-cloud.version>-->
            <spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
        </properties>
    
        <! -- Introducing Springcloud dependencies -->
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-dependencies</artifactId>
                    <version>${spring-cloud.version}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>Copy the code

    Troubleshooting:

    After checking the mapping between the latest SpringBoot version and SpringCloud version, we can change the version of SpringCloud to the latest official version hoxton.sr6 since the SpringBoot version we use is 2.3.0.

    <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <java.version>1.8</java.version>
            <! -- Spring Cloud version -->
            <spring-cloud.version>Hoxton.SR6</spring-cloud.version>
            <! -- <spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>-->
    </properties>Copy the code

    Add: the latest SpringBoot and SpringCloud version of the corresponding relationship to find, open the link to return a JSON array, after parsing can be.

    The official link: start. Spring. IO/physical/in…

    The version mappings are as follows:

    M2 :" spring Boot >= 2.0.0m3 and < 2.0.0m5 ", "Finchley. M3", "Spring Boot > = 2.0.0. M5 and < = 2.0.0. M5," "Finchley. M4" : "Spring Boot > = 2.0.0. The M6 and the < = 2.0.0. M6." "Finchley. M5" : "Spring Boot > = 2.0.0. M7 and < = 2.0.0. M7 Finchley.", "M6" : "Spring Boot > = 2.0.0. RC1 and <. = 2.0.0 RC1." M7: <=2.0.0.RC2 and <=2.0.0.RC2", Finchley.M9":"Spring Boot >=2.0.0.RELEASE and <=2.0.0.RELEASE", Finchley.RC1 :"Spring Boot >=2.0.1.RELEASE and <2.0.2.RELEASE", Finchley.RC2 :"Spring Boot >=2.0.2.RELEASE and <2.0.3.RELEASE", "Finchley.SR4":"Spring Boot >=2.0.3.RELEASE and <2.0.999. build-snapshot ", "Finchley. build-snapshot ":"Spring Boot >=2.0.999. build-snapshot and < 2.1.0.m3 ", "Greenwich.M1":"Spring Boot >= 2.1.0.m3 and < 2.1.0.release ", "Greenwich.SR6":"Spring Boot >= 2.1.0.release and <2.1.16. build-snapshot ", "Greenwich. Build-snapshot ":"Spring Boot >=2.1.16. build-snapshot and < 2.2.0.m4 ", "Hoxton.SR6":"Spring Boot >= 2.2.0.m4 and <2.3.2. build-snapshot ", "Hoxton. build-snapshot ":"Spring Boot >=2.3.2. build-snapshot and < 2.4.0.m1 ", "2020.0.0 - the SNAPSHOT", "Spring Boot > = 2.4.0. M1"}Copy the code