栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

springboot1.5升级到springboot2.x改造问题

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

springboot1.5升级到springboot2.x改造问题

最近在做服务化改造,从springboot1.5升级到springboot,遇到很多问题。包含mongodb、redis、yaml书写等方式发生了变化。整理如下:

1、MongoDB获取方式

DB获取方式从MongoTemplate变成MongoClient获取。
SpringBoot2.2.1及其以上版本中Sort不能直接实例化,需要使用Sort.by()来获取Sort对象

2、yaml格式书写

2.1 server.context-path 变成server:servlet.context-path
2.2 yaml名字不能有大写字母(根据注解方式)
Configuration property name ‘spring.gbDatasource’ is not valid:
Invalid characters: ‘D’
Bean: servletEndpointRegistrar
Reason: Canonical names should be kebab-case (’-’ separated), lowercase alpha-numeric characters and must start with a letter

3、kafka客户端版本

版本要调整


            org.springframework.kafka
            spring-kafka
            2.4.1.RELEASE
            
                
                    org.apache.kafka
                    kafka-clients
                
            
        
        
            org.apache.kafka
            kafka-clients
            2.4.1
        
4、SpringBoot启动报错:Failed to introspect Class [org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration] from ClassLoader [sun.misc.Launcher$AppClassLoader@4e0e2f2a]

这个是因为springboot服务和第三方库的springboot版本不一致导致的。

5、MongoDB改造 不兼容的类型: java.lang.String无法转换为java.util.List 6、mysql url配置

不能有配置转义,比如dbc:mysql://mysql:3306/car?useUnicode=true& characterEncoding=UTF-8&useSSL=false,还有就是2.0以上jdbc要加时区serverTimezone=Asia/Shanghai

7、jredis

同样的RedisCacheManager的配置方式也不能再以RedisTemplate为参数初始化

springboot2.2 spring-boot-starter-data-redis默认lettuce连接要么调整代码,要么去掉默认,添加原有的jedis


     org.springframework.boot
     spring-boot-starter-data-redis
     
         
             io.lettuce
             lettuce-core
         
     
 

    redis.clients
    jedis
    3.3.0

8、Jenkins构建报错:‘dependencies.dependency.version’ for… jar is missing

这个是domjar等有些jar是需要版本号的。

9、quarz框架

Active Scheduler of name ‘DefaultQuartzScheduler’ already registered in Quartz SchedulerRepository. Cannot create a new Spring-managed Scheduler of the same name!
这个情况和网上所述不一样。是因为在QuartzInitializerListener在新版本代码里已经生成了SchedulerFactory。这个情况就是写法是用springboot1.5方式,需要调整书写方式,springboot2.0
quartz不使用proterpeies方式,yaml文件如下:

datasource:
    type: com.zaxxer.hikari.HikariDataSource
    #账号配置
    url: jdbc:mysql://127.0.0.1:3306/quartz?useSSL=false&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&autoReconnectForPools=true
    username: admin
    password: lp10214
    driver-class-name: com.mysql.cj.jdbc.Driver
    #最小空闲连接数
    hikari:
      minimum-idle: 5 #最小连接数
      maximum-pool-size: 20  #池中最大连接数
      connection-timeout: 20000 #连接超时时间
      idle-timeout: 60000 # 空闲等待时间 ms
      auto-commit: true #
      max-lifetime: 1800000 #30分钟
      connection-test-query: SELECT 1
  quartz:
    #相关属性配置
    properties:
      org:
        quartz:
          scheduler:
            instanceName: CarQuartzScheduler
            instanceId: AUTO
          jobStore:
            class: org.quartz.impl.jdbcjobstore.JobStoreTX
            driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate
            tablePrefix: QRTZ_
            isClustered: false
            useProperties: false
          threadPool:
            class: org.quartz.simpl.SimpleThreadPool
            threadCount: 10
            threadPriority: 5
            threadsInheritContextClassLoaderOfInitializingThread: true
    #数据库方式
    job-store-type: jdbc
    #初始化表结构
    #jdbc:
    #initialize-schema: never
10、时间序列化

springboot1.5默认返回是时间戳,而springboot2.2默认是字符串。

11、mybatis高版本不支持localdatatime

mybatis中使用LocalDateTime报错:SQLFeatureNotSupportedException
降低mybatis版本或者数据库相关的还是使用jdbc的基本类型。

12、spring boot 2.x 接口返回时间类型不再自动序列化为timestamp
spring:
  jackson:
    serialization: 
      WRITE_DATES_AS_TIMESTAMPS: true
13、日志格式修改
logging:
  config: classpath:log4j2.xml
  level: info
 改为
logging:
  config: classpath:log4j2.xml
  level:
    root: info
http接口编码修改

新版本编码方式变了,需要修改为

server:
  tomcat:
    uri-encoding: UTF-8
spring:
  http:
    encoding:
      force: true
      charset: UTF-8
      enabled: true
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/332374.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号