• spring boot 1.x.x 到 spring boot 2.x.x 的那些变化


      spring boot1 到 spring boot2的配置变化很大,迁移项目到spring boot2过程中发现以下变化

      1.java 的 redis 配置添加了属性jedis

        旧版 

        spring:
          redis:
            timeout: 300000
            pool.max-active: 20
            pool.max-idle: 5
            pool.max-wait: -1
            pool.min-idle: 0

        新版

        spring:
          redis:
            timeout: 300000

            jedis:
              pool.max-active: 20
              pool.max-idle: 5
              pool.max-wait: -1
              pool.min-idle: 0

      2.tomcat 原来的线程池@bean配置不再支持,但yaml或properties配置没变

        yaml配置:

       server:
        tomcat:
        uri-encoding: utf-8
        max-threads: 1000
        max-connections: 900
        min-spare-threads: 100
       版本1的@bean配置:

        @Configuration
        public class TomcatConfig {

        @Bean
        public EmbeddedServletContainerFactory containerFactory() {
          TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
          factory.addConnectorCustomizers((connector) -> {
            Http11NioProtocol protocol = (Http11NioProtocol)connector.getProtocolHandler();
            protocol.setMaxConnections(1000);
            protocol.setMaxThreads(1000);
            protocol.setMinSpareThreads(100);
          });
          return factory;
          }

        }

      3.项目访问路径配置,版本2新加了servlet属性
      旧版:
      server:
       port: 8089
      context-path: /brieftkheal
      servlet-path: /
      新版:
      server:
        port: 8089
        servlet:
         context-path: /brieftkheal
         path: /
      4.实体类配置参数的prefix在新版本不让出现驼峰式命名,而是用‘-’分割开,如:
      旧版:
      @Component
      @ConfigurationProperties(prefix = "ipPhone")
      public class IpPhoneConfigProperties {
      private String url;
      private String id;
      private String key;
      private String pensionNumber;
       private Status status;
      private String ip1;
      private String ip2;
      private String eButlerPhoneWSUrl;
       。。。。。。
       public static class Status{
       private String success;
       private String noUser;
       private String noBalance;
       private String unknown;
         。。。。。。
       }
      }
      ipPhone:
       url:
       id:
       key:
      pensionNumber:
      ip1:
      ip2:
       eButlerPhoneWSUrl:
      status:
       success: 0
       noUser: 4
       noBalance: 16
       unknown: 999

      新版:
      @Component
      @ConfigurationProperties(prefix = "ip-phone")
      public class IpPhoneConfigProperties {
      private String url;
      private String id;
      private String key;
      private String pensionNumber;
       private Status status;
      private String ip1;
      private String ip2;
      private String eButlerPhoneWSUrl;
       。。。。。。
       public static class Status{
       private String success;
       private String noUser;
       private String noBalance;
       private String unknown;
         。。。。。。
       }
      }
      ip-phone:
       url:
       id:
       key:
      pensionNumber:
      ip1:
      ip2:
       eButlerPhoneWSUrl:
      status:
       success: 0
       noUser: 4
       noBalance: 16
       unknown: 999
      5.拦截器HandlerInterceptor 在2.0.0版本中默认拦截静态资源Resource
    HandlerMethod,跳过静态资源才走
    HandlerMethod对象的拦截,如果用swagger做接口api,需要加判断
    if(o instanceof HandlerMethod)
      6.spirngboot2.0版本全面支持java8,jpa的部分方法返回类型由原来的T变成了
    Optional<T>,如findById,findOne等方法,如要获取实体类T,用optional.get()方法
      7.RedisCacheManager类的配置变了,我目前没有找到配置方法,望指教
      8.spring文件上传配置有变化
      1.x版本:
      spring:

        http:
          multipart:
            max-file-size: 4MB
            max-request-size: 150MB

        2.x版本:

        spring: 

        servlet:
         multipart:
           max-file-size: 4MB
          max-request-size: 150MB
     
    好了,目前就发现这些,欢迎补充并指出不足

    
    
     
  • 相关阅读:
    deb包的2种安装安装方法
    苹果全系产品信息查询
    水货的运作流程
    关于手机字库损坏的真相
    关闭IOS更新功能(ios4/5/6)
    c++ builder xe2 字符串转日期
    《windows核心编程》 18章 堆
    《windows核心编程》 17章 内存映射文件
    使用内存映射文件来共享数据
    <转>C++位运算详解
  • 原文地址:https://www.cnblogs.com/zhzhair-coding/p/8669214.html
Copyright © 2020-2023  润新知