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客户端版本

版本要调整

<dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka</artifactId>
            <version>2.4.1.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.kafka</groupId>
                    <artifactId>kafka-clients</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka-clients</artifactId>
            <version>2.4.1</version>
        </dependency>

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<java.lang.String>

6、mysql url配置

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

7、jredis

同样的RedisCacheManager的配置方式也不能再以RedisTemplate为参数初始化
在这里插入图片描述
springboot2.2 spring-boot-starter-data-redis默认lettuce连接要么调整代码,要么去掉默认,添加原有的jedis

<dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-data-redis</artifactId>
     <exclusions>
         <exclusion>
             <groupId>io.lettuce</groupId>
             <artifactId>lettuce-core</artifactId>
         </exclusion>
     </exclusions>
 </dependency>
<dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
    <version>3.3.0</version>
</dependency>

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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值