Spring Boot: WebServerException: 无法启动嵌入式Tomcat

3

我正在尝试运行Spring Boot应用程序,但出现了异常。我已经尝试了许多答案,如运行mvn dependency:purge-local-repository然后运行mvn spring-boot:run,更新Spring Boot 2版本等,但没有一个能解决问题,因为我仍然在接收以下异常:

2019-12-05 00:06:00.787  INFO 19840 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2019-12-05 00:06:00.791  WARN 19840 --- [           main] o.a.c.loader.WebappClassLoaderBase       : The web application [ROOT] appears to have started a thread named [pool-1-thread-1] but has failed to stop it. This is very likely to create a memory leak. Stack tr
ace of thread:
 java.base@11.0.5/jdk.internal.misc.Unsafe.park(Native Method)
 java.base@11.0.5/java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:234)
 java.base@11.0.5/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2123)
 java.base@11.0.5/java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1182)
 java.base@11.0.5/java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:899)
 java.base@11.0.5/java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1054)
 java.base@11.0.5/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1114)
 java.base@11.0.5/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
 java.base@11.0.5/java.lang.Thread.run(Thread.java:834)
2019-12-05 00:06:00.793  WARN 19840 --- [           main] o.a.c.loader.WebappClassLoaderBase       : The web application [ROOT] appears to have started a thread named [pool-1-thread-2] but has failed to stop it. This is very likely to create a memory leak. Stack tr
ace of thread:
 java.base@11.0.5/jdk.internal.misc.Unsafe.park(Native Method)
 java.base@11.0.5/java.util.concurrent.locks.LockSupport.park(LockSupport.java:194)
 java.base@11.0.5/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2081)
 java.base@11.0.5/java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1177)
 java.base@11.0.5/java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:899)
 java.base@11.0.5/java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1054)
 java.base@11.0.5/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1114)
 java.base@11.0.5/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
 java.base@11.0.5/java.lang.Thread.run(Thread.java:834)
2019-12-05 00:06:00.795  WARN 19840 --- [           main] o.a.c.loader.WebappClassLoaderBase       : The web application [ROOT] appears to have started a thread named [HikariPool-1 housekeeper] but has failed to stop it. This is very likely to create a memory leak.
 Stack trace of thread:
 java.base@11.0.5/jdk.internal.misc.Unsafe.park(Native Method)
 java.base@11.0.5/java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:234)
 java.base@11.0.5/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2123)
 java.base@11.0.5/java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1182)
 java.base@11.0.5/java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:899)
 java.base@11.0.5/java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1054)
 java.base@11.0.5/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1114)
 java.base@11.0.5/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
 java.base@11.0.5/java.lang.Thread.run(Thread.java:834)
2019-12-05 00:06:00.798  WARN 19840 --- [           main] o.a.c.loader.WebappClassLoaderBase       : The web application [ROOT] appears to have started a thread named [HikariPool-1 connection adder] but has failed to stop it. This is very likely to create a memory
leak. Stack trace of thread:
 java.base@11.0.5/java.net.SocketInputStream.socketRead0(Native Method)
 java.base@11.0.5/java.net.SocketInputStream.socketRead(SocketInputStream.java:115)
 java.base@11.0.5/java.net.SocketInputStream.read(SocketInputStream.java:168)
 java.base@11.0.5/java.net.SocketInputStream.read(SocketInputStream.java:140)
 java.base@11.0.5/sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:448)
 java.base@11.0.5/sun.security.ssl.SSLSocketInputRecord.bytesInCompletePacket(SSLSocketInputRecord.java:68)
 java.base@11.0.5/sun.security.ssl.SSLSocketImpl.readApplicationRecord(SSLSocketImpl.java:1104)
 java.base@11.0.5/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:823)
 org.postgresql.core.VisibleBufferedInputStream.readMore(VisibleBufferedInputStream.java:140)
 org.postgresql.core.VisibleBufferedInputStream.ensureBytes(VisibleBufferedInputStream.java:109)
 org.postgresql.core.VisibleBufferedInputStream.read(VisibleBufferedInputStream.java:67)
 org.postgresql.core.PGStream.receiveChar(PGStream.java:306)
 org.postgresql.core.v3.ConnectionFactoryImpl.enableSSL(ConnectionFactoryImpl.java:405)
 org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:94)
 org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:192)
 org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
 org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195)
 org.postgresql.Driver.makeConnection(Driver.java:454)
 org.postgresql.Driver.connect(Driver.java:256)
 com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:119)
 com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369)
 com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198)
 com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467)
 com.zaxxer.hikari.pool.HikariPool.access$100(HikariPool.java:71)
 com.zaxxer.hikari.pool.HikariPool$PoolEntryCreator.call(HikariPool.java:706)
 com.zaxxer.hikari.pool.HikariPool$PoolEntryCreator.call(HikariPool.java:692)
 java.base@11.0.5/java.util.concurrent.FutureTask.run(FutureTask.java:264)
 java.base@11.0.5/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
 java.base@11.0.5/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
 java.base@11.0.5/java.lang.Thread.run(Thread.java:834)
2019-12-05 00:06:00.804  WARN 19840 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web serve
r; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
2019-12-05 00:06:00.805  INFO 19840 --- [           main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'application'
2019-12-05 00:06:00.806  INFO 19840 --- [           main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'security'
2019-12-05 00:06:00.807  INFO 19840 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2019-12-05 00:06:02.244  INFO 19840 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
2019-12-05 00:06:02.261  INFO 19840 --- [           main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-12-05 00:06:02.276 ERROR 19840 --- [           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:155) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:742) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:389) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:311) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1213) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1202) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
        at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
        at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:542) ~[na:na]
        at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:124) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:86) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
        at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:414) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
        at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:178) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:179) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:152) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
        ... 14 common frames omitted
Caused by: java.lang.IllegalArgumentException: Servlet must not be null
        at org.springframework.util.Assert.notNull(Assert.java:198) ~[spring-core-5.1.8.RELEASE.jar:5.1.8.RELEASE]
        at org.springframework.boot.web.servlet.ServletRegistrationBean.getDescription(ServletRegistrationBean.java:171) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
        at org.springframework.boot.web.servlet.RegistrationBean.onStartup(RegistrationBean.java:48) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:227) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
        at org.springframework.boot.web.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:53) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5132) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
        at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
        at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140) ~[na:na]
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
        at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
        at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
        at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140) ~[na:na]
        at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
        at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
        at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
        at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:932) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
        at org.apache.catalina.startup.Tomcat.start(Tomcat.java:456) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
        at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:105) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
        ... 19 common frames omitted

[WARNING]
java.lang.reflect.InvocationTargetException
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run (AbstractRunMojo.java:542)
    at java.lang.Thread.run (Thread.java:834)
Caused by: 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:155)
    at org.springframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java:543)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh (ServletWebServerApplicationContext.java:140)
    at org.springframework.boot.SpringApplication.refresh (SpringApplication.java:742)
    at org.springframework.boot.SpringApplication.refreshContext (SpringApplication.java:389)
    at org.springframework.boot.SpringApplication.run (SpringApplication.java:311)
    at org.springframework.boot.SpringApplication.run (SpringApplication.java:1213)
    at org.springframework.boot.SpringApplication.run (SpringApplication.java:1202)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run (AbstractRunMojo.java:542)
    at java.lang.Thread.run (Thread.java:834)
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize (TomcatWebServer.java:124)
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init> (TomcatWebServer.java:86)
    at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer (TomcatServletWebServerFactory.java:414)
    at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer (TomcatServletWebServerFactory.java:178)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer (ServletWebServerApplicationContext.java:179)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh (ServletWebServerApplicationContext.java:152)
    at org.springframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java:543)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh (ServletWebServerApplicationContext.java:140)
    at org.springframework.boot.SpringApplication.refresh (SpringApplication.java:742)
    at org.springframework.boot.SpringApplication.refreshContext (SpringApplication.java:389)
    at org.springframework.boot.SpringApplication.run (SpringApplication.java:311)
    at org.springframework.boot.SpringApplication.run (SpringApplication.java:1213)
    at org.springframework.boot.SpringApplication.run (SpringApplication.java:1202)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run (AbstractRunMojo.java:542)
    at java.lang.Thread.run (Thread.java:834)
Caused by: java.lang.IllegalArgumentException: Servlet must not be null
    at org.springframework.util.Assert.notNull (Assert.java:198)
    at org.springframework.boot.web.servlet.ServletRegistrationBean.getDescription (ServletRegistrationBean.java:171)
    at org.springframework.boot.web.servlet.RegistrationBean.onStartup (RegistrationBean.java:48)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize (ServletWebServerApplicationContext.java:227)
    at org.springframework.boot.web.embedded.tomcat.TomcatStarter.onStartup (TomcatStarter.java:53)
    at org.apache.catalina.core.StandardContext.startInternal (StandardContext.java:5132)
    at org.apache.catalina.util.LifecycleBase.start (LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase$StartChild.call (ContainerBase.java:1384)
    at org.apache.catalina.core.ContainerBase$StartChild.call (ContainerBase.java:1374)
    at java.util.concurrent.FutureTask.run (FutureTask.java:264)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute (InlineExecutorService.java:75)
    at java.util.concurrent.AbstractExecutorService.submit (AbstractExecutorService.java:140)
    at org.apache.catalina.core.ContainerBase.startInternal (ContainerBase.java:909)
    at org.apache.catalina.core.StandardHost.startInternal (StandardHost.java:841)
    at org.apache.catalina.util.LifecycleBase.start (LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase$StartChild.call (ContainerBase.java:1384)
    at org.apache.catalina.core.ContainerBase$StartChild.call (ContainerBase.java:1374)
    at java.util.concurrent.FutureTask.run (FutureTask.java:264)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute (InlineExecutorService.java:75)
    at java.util.concurrent.AbstractExecutorService.submit (AbstractExecutorService.java:140)
    at org.apache.catalina.core.ContainerBase.startInternal (ContainerBase.java:909)
    at org.apache.catalina.core.StandardEngine.startInternal (StandardEngine.java:262)
    at org.apache.catalina.util.LifecycleBase.start (LifecycleBase.java:183)
    at org.apache.catalina.core.StandardService.startInternal (StandardService.java:421)
    at org.apache.catalina.util.LifecycleBase.start (LifecycleBase.java:183)
    at org.apache.catalina.core.StandardServer.startInternal (StandardServer.java:932)
    at org.apache.catalina.util.LifecycleBase.start (LifecycleBase.java:183)
    at org.apache.catalina.startup.Tomcat.start (Tomcat.java:456)
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize (TomcatWebServer.java:105)
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init> (TomcatWebServer.java:86)
    at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer (TomcatServletWebServerFactory.java:414)
    at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer (TomcatServletWebServerFactory.java:178)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer (ServletWebServerApplicationContext.java:179)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh (ServletWebServerApplicationContext.java:152)
    at org.springframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java:543)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh (ServletWebServerApplicationContext.java:140)
    at org.springframework.boot.SpringApplication.refresh (SpringApplication.java:742)
    at org.springframework.boot.SpringApplication.refreshContext (SpringApplication.java:389)
    at org.springframework.boot.SpringApplication.run (SpringApplication.java:311)
    at org.springframework.boot.SpringApplication.run (SpringApplication.java:1213)
    at org.springframework.boot.SpringApplication.run (SpringApplication.java:1202)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run (AbstractRunMojo.java:542)
    at java.lang.Thread.run (Thread.java:834)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  37.901 s
[INFO] Finished at: 2019-12-05T00:06:03+05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.6.RELEASE:run (default-cli) on project sample-project: An exception occurred while running. null: InvocationTargetException: Unable to start web server; nested exception is org.
springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat: Servlet must not be null -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

我的主要 Spring Boot 文件是

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
@Configuration
@EnableAsync
public class SampleProject extends SpringBootServletInitializer {

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

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(SampleProject.class);
    }
}

我正在使用JDK 11.0.5。之前在Google App Engine上使用JDK 8运行,虽然一切正常,但异步调用却无法正常工作,因为我遇到了下面的错误。

意外出现错误(类型=内部服务器错误,状态=500)。Servlet和所有参与异步请求处理的过滤器都必须启用异步支持。这可以通过使用Servlet API中的Java代码或通过将“true”添加到web.xml中的Servlet和Filter声明来完成。

经过一些研究,我发现 GAE上的JDK8不支持NIO,所以我现在正在努力将其迁移到JDK 11。如有任何帮助,将不胜感激。谢谢!
更新:我的Servlet配置文件
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ServletConfig {
    @Bean
    public ServletRegistrationBean servletRegistrationBean() throws Exception {
        ServletRegistrationBean registrationBean = new ServletRegistrationBean();
        registrationBean.setLoadOnStartup(1);
        registrationBean.setAsyncSupported(true);
        return registrationBean;
    }
}

在删除可能冲突的Servlet配置文件后,我收到了以下错误:

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.springframework.data.rest.core.support.UnwrappingRepositoryInvokerFactory.<init>(UnwrappingRepositoryInvokerFactory.java:57)

The following method did not exist:

    org.springframework.plugin.core.PluginRegistry.of(Ljava/util/List;)Lorg/springframework/plugin/core/PluginRegistry;

The method's class, org.springframework.plugin.core.PluginRegistry, is available from the following locations:

    jar:file:/C:/Users/icurious/.m2/repository/org/springframework/plugin/spring-plugin-core/1.2.0.RELEASE/spring-plugin-core-1.2.0.RELEASE.jar!/org/springframework/plugin/core/PluginRegistry.class

It was loaded from the following location:

    file:/C:/Users/icurious/.m2/repository/org/springframework/plugin/spring-plugin-core/1.2.0.RELEASE/spring-plugin-core-1.2.0.RELEASE.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.plugin.core.PluginRegistry

Disconnected from the target VM, address: '127.0.0.1:0', transport: 'socket'

Process finished with exit code 1

你的应用程序中有一个ServletRegistrationBean,但是它的Servlet为空(null)。你是否在某个地方使用默认构造函数创建了一个Servlet,但未调用setServlet(Servlet)方法? - Andy Wilkinson
我还没有创建任何 ServletRegistrationBean,之前一直在使用嵌入式的Tomcat。 - iCurious
谢谢。如果你在自己的代码中没有创建,那么肯定是其他东西创建了。从你目前提供的信息中,我无法确定是什么创建了它。你能否分享一个最小化、完整化、可验证的示例,以便我们可以看到全貌? - Andy Wilkinson
嗨@AndyWilkinson,我提供了更多信息。我仍然遇到异常。此外,我已将我的Spring Boot Starter Parent版本更新为2.2.1.RELEASE。 - iCurious
第二个问题与第一个无关。Spring Boot 2.2中包含的Spring Data REST版本需要Spring Plugin 2.0,而您的类路径上有Spring Plugin 1.2。如果您需要帮助弄清楚为什么会发生这种情况,请提出一个新问题,并包括您的pom.xml的详细信息。 - Andy Wilkinson
3个回答

2
失败是因为您的应用程序包含一个具有空Servlet的ServletRegistrationBean。这是由于您的servletRegistrationBean引起的:
@Bean
public ServletRegistrationBean servletRegistrationBean() throws Exception {
    ServletRegistrationBean registrationBean = new ServletRegistrationBean();
    registrationBean.setLoadOnStartup(1);
    registrationBean.setAsyncSupported(true);
    return registrationBean;
}

当您创建一个 ServletRegistrationBean 时,需要提供要注册的 Servlet 。您可以通过将 Servlet 传递到 ServletRegistrationBean 的构造函数中,或通过调用 setServlet(Servlet)方法来实现。例如,假设您的 Servlet 类名为 YourServlet ,则可以执行以下操作:
@Bean
public ServletRegistrationBean servletRegistrationBean() throws Exception {
    ServletRegistrationBean registrationBean =
            new ServletRegistrationBean(new YourServlet());
    registrationBean.setLoadOnStartup(1);
    registrationBean.setAsyncSupported(true);
    return registrationBean;
}

1
在移除了ServletRegistrationBean后,我发现springfox-swagger 2.9.2版本不兼容JDK 11,所以我也将其移除。此外,我使用了(感谢Andy的提示)下面提到的spring-plugin-core,最终它起作用了!
    <dependency>
        <groupId>org.springframework.plugin</groupId>
        <artifactId>spring-plugin-core</artifactId>
        <version>2.0.0.RELEASE</version>
    </dependency>

0

检查所有实体中的@Column注释名称属性。您必须在表格/JPA实体中为两个属性使用相同的列名。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接