为什么我在将 spring-boot-starter-parent 父项目更新到最新的 2.2.5.RELEASE 后构建 Spring 引导项目时出现此错误?
Why am I obtaining this error building a Spring Boot project after updating the spring-boot-starter-parent parent project to the last 2.2.5.RELEASE?
我是 Spring Boot 的新手,我在尝试更新 spring-boot-starter 时遇到了一些问题-parent 父项目。
所以,一开始我有这个 pom.xml 文件(它工作正常,我可以构建项目并且没有问题):
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.springboot</groupId>
<artifactId>excel-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Excel API with Spring Boot</name>
<description>Spring Boot - working with Excel API</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-data</artifactId>
</dependency>
<!-- Start of excel dependencies -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.11</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.11</version>
</dependency>
<!-- End of excel dependencies -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
如您所见,此 pom.xml 文件包含此 部分:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
如果我做错了断言,请纠正我:据我了解,这意味着我的 pom.xml 文件是另一个 [= 的子文件spring-boot-starter-parent 项目的 65=] 文件具有版本 1.5.9.RELEASE.这个推理正确吗?如果在何处定义此 pom.xml 文件?
所以目前我成功地使用了这个父项目的 1.5.9.RELEASE 版本。它已经很旧了,我想将它更新到最后一个,即 2.2.5.RELEASE,如下所示:
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent
所以我只更改了之前 pom.xml 文件的 部分:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
问题是尝试通过此 Maven 命令构建项目:
mvn clean install -DskipTests=true
我收到以下错误消息:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/developer/git/SOC-dashboard/src/main/java/com/springboot/excelapi/Application.java:[6,44] package org.springframework.boot.web.support does not exist
[ERROR] /home/developer/git/SOC-dashboard/src/main/java/com/springboot/excelapi/Application.java:[9,34] cannot find symbol
symbol: class SpringBootServletInitializer
[ERROR] /home/developer/git/SOC-dashboard/src/main/java/com/springboot/excelapi/Application.java:[15,9] method does not override or implement a method from a supertype
[INFO] 3 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.349 s
[INFO] Finished at: 2020-03-20T05:48:14-07:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project excel-api: Compilation failure: Compilation failure:
[ERROR] /home/developer/git/SOC-dashboard/src/main/java/com/springboot/excelapi/Application.java:[6,44] package org.springframework.boot.web.support does not exist
[ERROR] /home/developer/git/SOC-dashboard/src/main/java/com/springboot/excelapi/Application.java:[9,34] cannot find symbol
[ERROR] symbol: class SpringBootServletInitializer
[ERROR] /home/developer/git/SOC-dashboard/src/main/java/com/springboot/excelapi/Application.java:[15,9] method does not override or implement a method from a supertype
[ERROR] -> [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/MojoFailureException
这是从 1.x 到 2.x 的主要 spring 版本升级。在此类主要版本升级过程中,通常会有重大更改,例如包重组、删除已弃用的 classes/methods 等。此类升级最好参考某种迁移指南。可以参考official migration guide or some of other blog such as this.
Spring 提供了一个可以添加到您的 pom 文件中的依赖模块。该模块分析应用程序并为所需的更改提供诊断输出。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-properties-migrator</artifactId>
<scope>runtime</scope>
</dependency>
针对问题中提出的具体问题;
[ERROR] /home/developer/git/SOC-dashboard/src/main/java/com/springboot/excelapi/Application.java:[9,34] cannot find symbol
[ERROR] symbol: class SpringBootServletInitializer
SpringBootServletInitializer
现在可以从 org.springframework.boot.web.servlet.support
包中获得。
我是 Spring Boot 的新手,我在尝试更新 spring-boot-starter 时遇到了一些问题-parent 父项目。
所以,一开始我有这个 pom.xml 文件(它工作正常,我可以构建项目并且没有问题):
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.springboot</groupId>
<artifactId>excel-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Excel API with Spring Boot</name>
<description>Spring Boot - working with Excel API</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-data</artifactId>
</dependency>
<!-- Start of excel dependencies -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.11</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.11</version>
</dependency>
<!-- End of excel dependencies -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
如您所见,此 pom.xml 文件包含此 部分:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
如果我做错了断言,请纠正我:据我了解,这意味着我的 pom.xml 文件是另一个 [= 的子文件spring-boot-starter-parent 项目的 65=] 文件具有版本 1.5.9.RELEASE.这个推理正确吗?如果在何处定义此 pom.xml 文件?
所以目前我成功地使用了这个父项目的 1.5.9.RELEASE 版本。它已经很旧了,我想将它更新到最后一个,即 2.2.5.RELEASE,如下所示:
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent
所以我只更改了之前 pom.xml 文件的 部分:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
问题是尝试通过此 Maven 命令构建项目:
mvn clean install -DskipTests=true
我收到以下错误消息:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/developer/git/SOC-dashboard/src/main/java/com/springboot/excelapi/Application.java:[6,44] package org.springframework.boot.web.support does not exist
[ERROR] /home/developer/git/SOC-dashboard/src/main/java/com/springboot/excelapi/Application.java:[9,34] cannot find symbol
symbol: class SpringBootServletInitializer
[ERROR] /home/developer/git/SOC-dashboard/src/main/java/com/springboot/excelapi/Application.java:[15,9] method does not override or implement a method from a supertype
[INFO] 3 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.349 s
[INFO] Finished at: 2020-03-20T05:48:14-07:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project excel-api: Compilation failure: Compilation failure:
[ERROR] /home/developer/git/SOC-dashboard/src/main/java/com/springboot/excelapi/Application.java:[6,44] package org.springframework.boot.web.support does not exist
[ERROR] /home/developer/git/SOC-dashboard/src/main/java/com/springboot/excelapi/Application.java:[9,34] cannot find symbol
[ERROR] symbol: class SpringBootServletInitializer
[ERROR] /home/developer/git/SOC-dashboard/src/main/java/com/springboot/excelapi/Application.java:[15,9] method does not override or implement a method from a supertype
[ERROR] -> [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/MojoFailureException
这是从 1.x 到 2.x 的主要 spring 版本升级。在此类主要版本升级过程中,通常会有重大更改,例如包重组、删除已弃用的 classes/methods 等。此类升级最好参考某种迁移指南。可以参考official migration guide or some of other blog such as this.
Spring 提供了一个可以添加到您的 pom 文件中的依赖模块。该模块分析应用程序并为所需的更改提供诊断输出。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-properties-migrator</artifactId>
<scope>runtime</scope>
</dependency>
针对问题中提出的具体问题;
[ERROR] /home/developer/git/SOC-dashboard/src/main/java/com/springboot/excelapi/Application.java:[9,34] cannot find symbol
[ERROR] symbol: class SpringBootServletInitializer
SpringBootServletInitializer
现在可以从 org.springframework.boot.web.servlet.support
包中获得。