Spring Boot 项目编译时提示错误 cannot access WebApplicationInitializer 错误

具体的提示信息如下:

Error:(21, 8) java: cannot access org.springframework.web.WebApplicationInitializer
  class file for org.springframework.web.WebApplicationInitializer not found



这个错误要结合你的 Application 代码来看。

因为在 Application 的代码中,我们继承了 SpringBootServletInitializer。

请注意:我们定义的 Application:

public class Application extends SpringBootServletInitializer{
}

正是因为这个定义,所以你的 POM 或者 build.gradle 中 需要添加:spring-boot-starter-web 依赖。

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

然后你再次编译的项目,你就不会有提示编译错误了。

https://www.cwiki.us/display/SpringBootZH/questions/57939020

原文地址:https://www.cnblogs.com/huyuchengus/p/12694765.html