Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat


  在使用Eureka時出現 Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat錯誤。

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-08-07 11:00:39.609 ERROR 16772 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:161) ~[spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:545) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
    at com.yxw.springcloud.Eureka1Config.main(Eureka1Config.java:12) [classes/:na]
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat

排查是不是yml文件的錯誤  

server:
  port: 8081

spring:
  application:
    name: server-euerka

# Eureka配置
eureka:
  instance:
    hostname: localhost #eureka服務端的實列名稱
  client:
    register-with-eureka: false # 表示是否向eureka注冊中心注冊自己
    fetch-registry: false # 如果為false,表示自己為注冊中心
    service-url: #監控頁面
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

在看一下是不是jdk的問題,相比較於jdk1.8以上的版本缺少了依賴包。

要使JAXBAPI在運行時可用,請指定以下命令行選項:
--add-modules java.xml.bind

快速和骯臟的解決方案:(僅JDK 9/10)
要使JAXBAPI在運行時可用,請指定以下命令行選項:
--add-modules java.xml.bind

但是我仍然需要這個來使用Java 8

如果您嘗試指定--add-modules對於舊的JDK,它會崩潰,因為它是一個無法識別的選項。我建議兩種選擇之一:

通過檢查JDK版本,可以在啟動腳本(如果有)中有條件地應用參數$JAVA_HOME/release為JAVA_VERSION。
您可以添加-XX:+IgnoreUnrecognizedVMOptions讓JVM默默地忽略不可識別的選項,而不是崩潰。但要小心!您使用的任何其他命令行args都將不再由JVM對您進行驗證。此選項適用於Oracle/OpenJDK以及IBMJDK(截至JDK8sr4)
替代快速解決方案:(僅限於JDK 9/10)

注意,您可以通過指定--add-modules java.se.ee選擇。這,這個,那,那個java.se.ee模塊是一個聚合模塊,它包括java.se.ee以及上面的JavaEEAPI模塊。

正確的長期解決方案:(所有JDK版本)

上面列出的JavaEEAPI模塊都有標記@Deprecated(forRemoval=true)因此,它們可能會在Java 11中被刪除。所以--add-moduleJava 11中的方法將不再有效。

在Java 11和后續中,您需要做的是在類路徑或模塊路徑上包含您自己的JavaEEAPI副本。例如,可以將JAX-BAPI添加為maven依賴項
View Code
<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.0</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-core</artifactId>
    <version>2.3.0</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.3.0</version>
</dependency>

如果還是不行那應該就是版本不兼容了,spring cloud我用的Greenwich版本,spring boot用的是2.1.6,現在換成新一點的2.2.2就出問題了,那就用回低版本吧。

<!--            springcloud依賴-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Greenwich.SR1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

<!--            spring-boot依賴-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>2.1.2.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

spring-boot於spring-cloud對應版本:https://www.jianshu.com/p/29ee7dddcbae


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM