专注于 JetBrains IDEA 全家桶,永久激活,教程
持续更新 PyCharm,IDEA,WebStorm,PhpStorm,DataGrip,RubyMine,CLion,AppCode 永久激活教程

SpringBoot 1.4.0升级2.2.6版本后遇到的问题总结

SpringBoot版本从1.4.0升级为版本2.2.6

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <!--<version>1.4.0.RELEASE</version>-->
        <version>2.2.6.RELEASE</version>
    </parent>

SpringCloud版本升级为对应匹配Hoxton.SR4

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <!--<version>Brixton.SR3</version>-->
                <version>Hoxton.SR4</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

1、Sort排序时遇到的问题 has private access in ‘org.springframework.data.domain.Sort’

原因:springboot2.2.1(含)以上的版本Sort已经不能再实例化了,构造方法已经是私有的了!

解决方法:改用Sort.by获得Sort对象

//旧版本
query.with(new Sort(Direction.DESC, "createTime"));       

//新版本
query.with(Sort.by(Direction.ASC, "createTime"));

2、不兼容的类型: com.mongodb.client.result.UpdateResult无法转换为com.mongodb.WriteResult

解决方法:WriteResult 替换 UpdateResult

3、对于BasicQuery(com.mongodb.BasicDBObject,com.mongodb.BasicDBObject), 找不到合适的构造器

原因: mongodb中QueryBuilder中DBObject被弃用,改为Document构造的解决方式

解决方法:Document 替换 BasicDBObject

//旧版本
Query query = new BasicQuery(new BasicDBObject(),new BasicDBObject());

//新版本
Query query = new BasicQuery(new Document(),new Document());

4、Caused by: java.lang.ClassNotFoundException: org.apache.commons.pool2.impl.GenericObjectPoolConfig

原因:缺少因commons-pool2的依赖包

解决方法:添加下面依赖

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-pool2</artifactId>
    <version>2.0</version>
</dependency>

5、启动报错提示 nested exception is java.lang.NoClassDefFoundError: redis/clients/jedis/JedisPoolConfig

原因:缺少Jedis的依赖

解决方法:添加下面依赖

<dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
</dependency>

6、org.springframework.cloud.config.client.DiscoveryClientConfigServiceBootstrapConfiguration required a bean of type ‘org.springframework.cloud.client.discovery.DiscoveryClient’ that could not be found.

原因:缺少注解@EnableDiscoveryClient

@SpringBootApplication
//版本升级后添加
@EnableDiscoveryClient
@EnableEurekaClient
@EnableCircuitBreaker
@ComponentScan(basePackages =
{ "com.Demo.test" })
public class Application{}

7、springboot从1.3.5升级为2.2.6后@SpringApplicationConfiguration注解报错

原因:这个注解在1.4就被替换了,较新版的Spring Boot取消了@SpringApplicationConfiguration这个注解

解决方法:springboot1.4版本以及以后的版本,使用@SpringBootTest

8、Loading class `com.mysql.jdbc.Driver’. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver’. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

原因:提示信息表明数据库驱动com.mysql.jdbc.Driver’已经被弃用了、应当使用新的驱动com.mysql.cj.jdbc.Driver’

解決方法:

#修改前
#driverClassName: com.mysql.jdbc.Driver
#修改后
 driverClassName: com.mysql.cj.jdbc.Driver

9、Parameter 0 of method linkDiscoverers in org.springframework.hateoas.config.HateoasConfiguration required a single bean, but 15 were found:

原因:swagger版本不匹配

解決方式:

<!-- swagger依赖 -->
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <!--<version>2.2.2</version>-->     <!--修改前版本-->
        <version>2.6.1</version>            <!--修改后版本-->
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <!--<version>2.2.2</version>-->    <!--修改前版本-->
        <version>2.6.1</version>           <!--修改后版本-->
    </dependency>

10、部分依赖artifactid发生变化的。例如用到eureka、ribbon等依赖的需要将依赖artifactid改成新版本对应的名称。

例如

ribbon依赖修改

#修改前
<artifactId>spring-cloud-starter-ribbon</artifactId>
#修改后
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>

eureka依赖修改

#修改前
<artifactId>spring-cloud-starter-eureka</artifactId>
#修改后
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>

hystrix依赖修改

<!-- hystrix依赖 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            #修改前
            <!--<artifactId>spring-cloud-starter-hystrix</artifactId>-->
            #修改后
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>

文章永久链接:https://tech.souyunku.com/48462

未经允许不得转载:搜云库技术团队 » SpringBoot 1.4.0升级2.2.6版本后遇到的问题总结

JetBrains 全家桶,激活、破解、教程

提供 JetBrains 全家桶激活码、注册码、破解补丁下载及详细激活教程,支持 IntelliJ IDEA、PyCharm、WebStorm 等工具的永久激活。无论是破解教程,还是最新激活码,均可免费获得,帮助开发者解决常见激活问题,确保轻松破解并快速使用 JetBrains 软件。获取免费的破解补丁和激活码,快速解决激活难题,全面覆盖 2024/2025 版本!

联系我们联系我们