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


免責聲明!

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



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