首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么在将Spring启动父项目更新到最后2.2.5.RELEASE之后,生成spring项目时出现了这个错误?

为什么在将Spring启动父项目更新到最后2.2.5.RELEASE之后,生成spring项目时出现了这个错误?
EN

Stack Overflow用户
提问于 2020-03-20 13:05:04
回答 1查看 3.6K关注 0票数 1

我在spring-boot-starter-parent Spring Boot中非常新,在更新父项目时遇到了一些问题。

因此,在开始时,我有这个pom.xml文件(它工作得很好,我可以构建这个项目,我没有问题):

代码语言:javascript
复制
<?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文件包含以下部分:

代码语言:javascript
复制
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.9.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

如果我做错了断言,请纠正我:根据我所理解的,这意味着我的spring-boot-starter-parent pom.xml文件是具有1.5.9.RELEASE.版本的1.5.9.RELEASE.项目的另一个pom.xml文件的子文件。这个推理正确吗?万一在哪里定义了这个pom.xml文件?

因此,目前我成功地使用了这个父项目的1.5.9.RELEASE版本。它很老了,我想将它更新为最后一个2.2.5.RELEASE,,如下所示:

https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent

因此,我只以这种方式更改了前一个pom.xml文件的部分:

代码语言:javascript
复制
<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命令构建项目:

代码语言:javascript
复制
mvn clean install -DskipTests=true

我获得以下错误消息:

代码语言:javascript
复制
[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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-25 09:20:23

这是一个主要的春季版本从1.x升级到2.x。在这样的主要版本升级过程中,通常会出现诸如包重构、删除不推荐的类/方法等重大更改。最好参考某种迁移指南来进行此类升级。您可以参考官方移民指南或其他一些博客,如

Spring提供了一个依赖模块,它可以添加到pom文件中。该模块分析应用程序,并为所需的更改提供诊断输出。

代码语言:javascript
复制
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-properties-migrator</artifactId>
    <scope>runtime</scope>
</dependency>

针对问题中提出的具体问题;

代码语言:javascript
复制
[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包中获得。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60774767

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档