将 Spring Boot 1.5.10 升级到 2.1.11

Posted

技术标签:

【中文标题】将 Spring Boot 1.5.10 升级到 2.1.11【英文标题】:Upgrade Spring boot 1.5.10 to 2.1.11 【发布时间】:2020-04-29 20:50:45 【问题描述】:

我是弹簧靴的新手。我正在尝试将 spring boot 1.5.10 升级到 2.1.11。现在我有这个错误,我不知道如何解决它

重新启动我的应用程序类时出现异常。

线程“main”中的异常 java.lang.reflect.InvocationTargetException 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在 java.lang.reflect.Method.invoke(Method.java:498) 在 com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:66) 引起:java.lang.AbstractMethodError: org.springframework.boot.context.config.ConfigFileApplicationListener.supportsSourceType(Ljava/lang/Class;)Z

这是我添加了依赖项的 POM.xml。

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
             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.academy</groupId>
        <artifactId>search</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>jar</packaging>
        <name>search</name>
        <description>fetch search results</description>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.1.11.RELEASE</version>
            <relativePath/>
        </parent>
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <java.version>1.8</java.version>
            <spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
            <sleuth.version>2.0.1.RELEASE</sleuth.version>
            <docker.image.prefix>academy</docker.image.prefix>
        </properties>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-properties-migrator</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter</artifactId>
            </dependency>
            <dependency>
                <groupId>org.apache.camel</groupId>
                <artifactId>camel-spring-boot-starter</artifactId>
                <version>2.24.2</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-sleuth</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>pl.project13.maven</groupId>
                <artifactId>git-commit-id-plugin</artifactId>
                <version>4.0.0</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-jersey</artifactId>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.16.16</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>com.academy</groupId>
                <artifactId>integration-framework</artifactId>
                <version>0.0.1</version>
            </dependency>
            <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-core</artifactId>
                <version>3.1.0</version>
            </dependency>
        </dependencies>
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-dependencies</artifactId>
                    <version>$spring-cloud.version</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
                <dependency>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-starter-sleuth</artifactId>
                    <version>$sleuth.version</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>0.8.1</version>
                    <executions>
                        <execution>
                            <id>default-prepare-agent</id>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>default-report</id>
                            <goals>
                                <goal>report</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>default-check</id>
                            <goals>
                                <goal>check</goal>
                            </goals>
                            <configuration>
                                <rules>
                                    <rule implementation="org.jacoco.maven.RuleConfiguration">
                                        <element>BUNDLE</element>
                                        <limits>
                                            <limit implementation="org.jacoco.report.check.Limit">
                                                <counter>COMPLEXITY</counter>
                                                <value>COVEREDRATIO</value>
                                                <minimum>0.90</minimum>
                                            </limit>
                                        </limits>
                                    </rule>
                                </rules>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </project>

Please help me.

【问题讨论】:

运行mvn spring-boot:run 并发布控制台输出。 @EugenCovaci [INFO] --- spring-boot-maven-plugin:2.1.11.RELEASE:run (default-cli) @search --- [WARNING] java.lang.reflect。在 sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) 在 sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) 在 java.lang.reflect 的 InvocationTargetException。 Method.invoke (Method.java:498) at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run (AbstractRunMojo.java:543) at java.lang.Thread.run (Thread.java:748) 引起:java.lang.AbstractMethodError: org.springframework.boot.context.config.ConfigFileApplicationListener.supportsSourceType(Ljava/lang/Class;)Z at org.springframework.context.event.GenericApplicationListenerAdapter。 supportsSourceType (GenericApplicationListenerAdapter.java:81) at org.springframework.context.event.AbstractApplicationEventMulticaster.supportsEvent (AbstractApplicationEventMulticaster.java:295) at org.springframework.context.event.AbstractApplicationEventMulticaster.retrieveApplicationListeners (AbstractApplicationEventMulticaster.java:225) 构建失败 [信息] ------------------------- ------------------------------------------------ [INFO] 总时间:8.651 s [INFO] 完成时间:2020 -01-13T15:37:24+05:30 [信息] --------------------------------- ------------------------------------- [错误] 执行目标 org.springframework.boot 失败: spring-boot-maven-plugin:2.1.11.RELEASE:run (default-cli) on project search: 运行时发生异常。 null: InvocationTargetException: org.springframework.boot.context.config.ConfigFileApplicationListener.supportsSourceType(Ljava/lang/Class;)Z -> [帮助1] 你的java版本java -version是什么,你的mvn dependency:tree输出是什么?很可能您的库版本不匹配。 【参考方案1】:

很可能您的 Spring Cloud 版本与您的 Spring 版本(和 Spring Boot)不兼容。 Spring Cloud 的最新版本是 2.2.1。

哦,当你正在更新到 Spring Boot 2.2.2 时,因为 2.1.x 即将结束生命。

【讨论】:

感谢您的回复。所以我应该直接升级到2.2.1? @RohiniTurkar 是的,但要准备好对代码进行更改。去年年底,我将主要系统从 Spring Boot 1.4 升级到 2.2。它进行得很顺利,但也有一些令人讨厌的惊喜。 我更改为 spring 2.2.0 版本。现在我得到了错误。原因:java.io.FileNotFoundException:类路径资源[org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.class]无法打开,因为它不存在 云版本:Greenwich.BUILD-SNAPSHOT

以上是关于将 Spring Boot 1.5.10 升级到 2.1.11的主要内容,如果未能解决你的问题,请参考以下文章

Spring boot:REST API 行为不一致后版本升级

将 Spring Boot 升级到 2.4.1

将 Spring Boot 2.3.5 升级到 2.4.0

将 Web 应用升级到 Spring Boot 2.4 后出现 IllegalStateException

将 Spring Boot 从 2.4.X 升级到 2.6.X 后无法运行我的 jar

TypeNotPresentExceptionProxy,将Spring Boot Starter父级从2.1.8升级到2.2.1