具體的提示信息如下:
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