springboot 1.5.x升级2.1.18 踩坑

  1. Narayana支持已被删除,pom中删除相关依赖 spring-boot-starter-jta-narayana。
  2. java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.<init>([Ljava/lang/Object;)V

    升级spring-cloud 版本至 Greenwich.SR6

  3. ChannelAwareMessageListener 包路径更改为 org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener 
  4. HttpMessageConverters 包路径更改为 org.springframework.boot.autoconfigure.http.HttpMessageConverters
  5. 依赖修改

    <dependency>
         <groupId>org.springframework.cloud</groupId>
         <artifactId>spring-cloud-starter-feign</artifactId>
    </dependency>

    修改为

    <dependency>
        <groupId>org.springframework.cloud</groupId>
         <artifactId>spring-cloud-starter-openfeign</artifactId>
     </dependency>

  6. 依赖修改

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka</artifactId>
    </dependency>

    修改为

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
    </dependency>

  7. 依赖修改

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-hystrix</artifactId>
    </dependency>

    修改为

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
    </dependency>

  8. 依赖修改

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-ribbon</artifactId>
    </dependency>

    修改为

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
    </dependency>

  9. FeignClient 包路径更改为 org.springframework.cloud.openfeign.FeignClient

  10. EnableFeignClients 包路径更改为 org.springframework.cloud.openfeign.EnableFeignClients

  11. The bean 'operationConnFactory', defined in class path resource [com/yiche/ycapp/server/video/mq/VideoAddRecordConfig.class], could not be registered. A bean with that name has already been defined in class path resource [com/yiche/ycapp/server/video/mq/OperationRecordConfig.class] and overriding is disabled.

    Action:

    Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
    默认情况下,Bean覆盖已被禁用。yml 中增加 spring.main.allow-bean-definition-overriding=true

  12. java.lang.NullPointerException: null
    at com.alibaba.druid.pool.vendor.MySqlValidConnectionChecker.<init>(MySqlValidConnectionChecker.java:48)
    at com.alibaba.druid.pool.DruidDataSource.initValidConnectionChecker(DruidDataSource.java:878)
    at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:594)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod

    升级 druid 版本至  1.2.3
  13. nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'operationRabbitTemplate': Requested bean is currently in creation: Is there an unresolvable circular reference?

    @Configuration的修饰的继承关系的类,子类不能@Autowired 父类初始化的Bean,需要父类定义 成员变量,子类使用父类的成员变量。

  14. Configuration property name 'outRequestUrl' is not valid:

    Invalid characters: 'R', 'U'
    Bean: scopedTarget.commentConfig
    Reason: Canonical names should be kebab-case ('-' separated), lowercase alpha-numeric characters and must start with a letter

    Action:

    Modify 'outRequestUrl' so that it conforms to the canonical names requirements.

    需要全部小写用 - 隔开,小写必须是字母开头 :@ConfigurationProperties(prefix = "outRequestUrl") 修改为 @ConfigurationProperties(prefix = "out-request-url")

  15. 配置@ResponseBody注解依然返回xml格式的数据
    pom 排除  jackson-dataformat-xml

  16. discard long time none received connection. , jdbcUrl : jdbc:mysql://192.168.15.127:3306/ycapp_video?useSSL=false, jdbcUrl : jdbc:mysql://192.168.15.127:3306/ycapp_video?useSSL=false, lastPacketReceivedIdleMillis : 125807
    升级 druid 版本至  1.2.3+ (升级后,此报警为WARN,如果不想输出,调整logback.xml中druid包的日志输出级别 <logger name="com.alibaba.druid.pool" level="ERROR"/> )
  17. 1111

  18. 如果项目中使用了jedis,需要手动引入jedis的包,springboot 2之后默认引入lettce的包
  19. 如果报多个cacheManage ,检查是否引用的op-sso这个包,如果引用了,自己的cacheManage必须叫
    RedisCacheManager
  20. 如果rabbitTemple无法生成,报

    Requested bean is currently in creation: Is there an unresolvable circular reference?

    修改
    management:
      health:
        rabbit:
          enabled: false
  21. 如果之前没有现式的引用web包,需要引入
    <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    
    
  22. op-sso 1.3.7 需要升级 成支持2.2.1的版本
  23. org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder 修改为
    org.springframework.boot.jdbc.DataSourceBuilder。
  24. reids cacheManager升级

    @Bean
     @Primary
     public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {
         RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig()
                 .entryTtl(Duration.ofSeconds(86400)); // 设置缓存有效期一小时
         return RedisCacheManager
                 .builder(RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory))
                 .cacheDefaults(redisCacheConfiguration).build();
     }

  25. 自定义endpoint监控项升级,使用注解替代原来的继承方法,invoke方法替换为endpoint方法

    @Configuration
    @Endpoint(id = "hystrix-endpoint")
    public class HystrixEndpoint {
     
        @ReadOperation
        public Map<String, Integer> endpoint() {
            return MyCommand.getAll();
        }

  26. HikariPool-1 - jdbcUrl is required with driverClassName..
    如果DataSource 初始化bean是通过   DataSourceBuilder.create().build() ,springboot 1.5.x 默认采用的是 org.apache.tomcat.jdbc.pool.DataSource,而 2.0+采用的是 HikariDataSource。
    pom中排除  HikariCP,加上  tomcat-jdbc

    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <exclusions>
            <exclusion>
                <artifactId>HikariCP</artifactId>
                <groupId>com.zaxxer</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-jdbc</artifactId>
    </dependency>

  27. mongodb 的api修改, mongoTemplate.find(queryBuilder,Class,collection) 已废弃,替代为 mongoTemplate.find(query,Class,collection),实现功能 根据条件(指定列表中的uid)查询指定 collection,返回包含指定字段(keys)的对象集合

    // 原代码
        @Override
        public List<UserFullInfo> getUserInfoList(List<Integer> uidList, String[] keys) {
            String uid = "uid";
            DBObject queryBuilder = new BasicDBObject();
            Document subQuery = new Document();
            subQuery.append("$in", uidList);
            queryBuilder.put(uid, subQuery);
            BasicDBObject fields = new BasicDBObject().append("_id"false);
            String[] fs = keys;
            boolean includeUid = false;
            for (String f : fs) {
                includeUid = f.equals(uid);
                fields.append(f, true);
            }
            if (!includeUid) {
                fields.append(uid, true);
            }
         
            List<UserFullInfo> value = mongoTemplate.find(queryBuilder
                    , UserFullInfo.class, COLLECTION_USER);
        }
    // 修改后代码
        @Override
        public List<UserFullInfo> getUserInfoList(List<Integer> uidList, String[] keys) {
            String uid = "uid";
         
            List<String> fields = Arrays.asList(keys);
            Query query = new Query(Criteria.where("uid").in(uidList));
            Field findFields = query.fields();
         
            if (!CollectionUtils.isEmpty(fields)) {
                fields.forEach(findFields::include);
            }
            if (!fields.contains("uid")) {
                findFields.include(uid);
            }
            List<UserFullInfo> value = mongoTemplate.find(query
                    , UserFullInfo.class, COLLECTION_USER);
        }

     

  28. java.lang.ClassNotFoundException: org.springframework.boot.bind.RelaxedPropertyResolver
    可能是版本冲突问题,此项目冲突的包为  spring-boot-admin-starter-client ,版本升级:1.5.7 → 2.3.0
  29. The following method did not exist: org.elasticsearch.common.logging.Loggers.getLogger(Ljava/lang/String;)Lorg/apache/logging/log4j/Logger;
    是因为 org.elasticsearch.client 包中引入了低版本的  transport-netty4-client jar,把 elasticsearch包 中 排除掉,重新引入 transport-netty4-client 包,和 elasticsearch 版本保持一致即可。

    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>transport</artifactId>
        <version>6.8.0</version>
        <exclusions>
            <exclusion>
                <artifactId>elasticsearch</artifactId>
                <groupId>org.elasticsearch</groupId>
            </exclusion>
            <exclusion>
                <artifactId>transport-netty4-client</artifactId>
                <groupId>org.elasticsearch.plugin</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.plugin</groupId>
        <artifactId>transport-netty4-client</artifactId>
        <version>6.8.0</version>
        <scope>compile</scope>
    </dependency>

  30. Bean with name 'vf_VideoServiceImpl' has been injected into other beans [videoForumServiceImpl] in its raw version as part of a circular reference, 循环依赖,在引入上 增加 @Lazy
  31. Field commentApi in com.yiche.video.core.feign.comment.CommentClient required a bean of type 'com.yiche.video.core.feign.comment.CommentApi' that could not be found. 因为 第10条中 

    EnableFeignClients 包路径更改为 org.springframework.cloud.openfeign.EnableFeignClients 变更了 FeignClient 的路径,改成了 openfeign。所以包引入的路径 org.springframework.cloud.netflix.feign.FeignClient 要改成org.springframework.cloud.openfeign.FeignClient;

  32. 如果编译报找不到cat-clint1.3.6

    <dependency>
         <groupId>com.dianping.cat</groupId>
         <artifactId>cat-core</artifactId>
         <version>${cat.version}</version>
         <exclusions>
             <exclusion>
                 <artifactId>cat-client</artifactId>
                 <groupId>com.dianping.cat</groupId>
             </exclusion>
         </exclusions>
     </dependency>
     <dependency>
         <groupId>com.dianping.cat</groupId>
         <artifactId>cat-client</artifactId>
         <version>3.0.0</version>
     </dependency>

  33. Attempting to connect to: [192.168.87.53:5672, 192.168.87.54:5672, 192.168.87.52:5672]
    org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect
    场景是:原项目引用  spring-cloud-starter-bus-amqp ,但没有使用mq(mq地址错误),1.5.x 版本不会自动创建链接,只会初始化工厂类(CachingConnectionFactory)。
    spring-rabbit-2.1.17.RELEASE 初始化工厂类后会尝试连接(失败后重连,且是同步操作),严重阻塞启动时长(原来20s,现在要300s),解决方案是去掉该项目的mq包。

     
  34. 如果项目启动报
    java.lang.NoClassDefFoundError: org/apache/log4j/Logger 需要手动引入log4j的包
    
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
        <scope>compile</scope>
    </dependency>

更多可以查看 从Spring Boot 2.0升级 2.1.x

成为第一个赞同者

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值