zoukankan      html  css  js  c++  java
  • SpringBoot2.2发行版新特性

    Spring Framework升级

    SpringBoot2.2的底层Spring Framework版本升级为5.2

    JMX默认禁用

    默认情况下不再启用JMX。 可以使用配置属性spring.jmx.enabled = true启用此功能。 如果您使用IDE功能来管理应用程序,则可能还要在该位置启用该标志。

    Java 13支持

    Spring Boot 2.2增加了对Java 13的支持。还支持Java 8和11。

    性能提升

    通过使用proxyBeanMethods=falseSpring Boot的@Configuration类,减少了启动时间和内存使用量。 proxyBeanMethods@ConfigurationSpring Framework 5.2 M1中引入的新属性。 proxyBeanMethods也可作为一个属性@SpringBootApplication@SpringBootConfiguration

    在使用bootRunGradle或spring-boot:runMaven 在开发时启动应用程序时,JVM将配置有标志(-Xverify:none-XX:TieredStopAtLevel=1)以对其进行优化以减少启动时间。在JDK 13上运行时,-Xverify:none未指定,因为已弃用。

    此版本中还进行了其他一些性能改进:

    • 绑定大量配置属性所需的时间已大大减少
    • 当Spring Boot PersistenceUnit通过扫描JPA实体完全准备一个时,由于它是冗余的,因此Hibernate自己的实体扫描已被禁用
    • 自动配置中的注入点已经过改进,仅适用于必须创建bean的情况
    • 现在仅在启用和公开端点的情况下(通过JMX或HTTP)创建与Actuator端点相关的Bean。
    • 编解码器自动配置的条件已得到改善,以便在不再使用编解码器时不再对其进行配置
    • Tomcat的MBean注册表默认情况下处于禁用状态,从而将Tomcat的内存占用量减少了大约2MB

    延迟初始化

    现在可以通过该spring.main.lazy-initialization属性启用全局延迟初始化以减少启动时间。请注意,使用该功能可能需要付出一定的成本或者代价:

    • 在进行任何延迟的初始化时,HTTP请求的处理可能需要更长的时间
    • 现在,通常不会在启动时发生故障,直到以后

    通过使用注释各自的定义,各个bean可以选择退出延迟初始化@Lazy(false)。如果无法@Lazy(false)选择退出延迟初始化,LazyInitializationExcludeFilter则可以使用Bean代替。例如,要永远不要将IntegrationFlowbean 设置为惰性,可以使用以下代码:

    @Bean
    static LazyInitializationExcludeFilter integrationLazyInitExcludeFilter() {
        return LazyInitializationExcludeFilter.forBeanTypes(IntegrationFlow.class);
    }

    JUnit 5

    spring-boot-starter-test现在默认提供JUnit 5。默认情况下,包括JUnit 5的老式引擎以支持现有的基于JUnit 4的测试类,以便您可以在准备好迁移到JUnit 5时进行迁移。也可以在同一模块中混合使用基于JUnit 4和基于JUnit 5的测试类。这使您可以根据需要逐步迁移到JUnit 5。

    请注意,JUnit 4的Maven Surefire插件不支持该listener属性。如果您具有类似于以下内容的Maven配置:

    <configuration>
        <properties>
            <property>
                <name>listener</name>
                <value>com.example.CustomRunListener</value>
            </property>
        </properties>
    </configuration>

    不能使用,junit-vintage-engine而需要显式回滚到JUnit 4:

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.jupiter</groupId>
                    <artifactId>junit-jupiter</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.mockito</groupId>
                    <artifactId>mockito-junit-jupiter</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
    </dependencies>

    DataSource 健康监控

    DataSource健康指标包含一个额外的validationQuery与反对使用的验证查询属性DataSource。同样,该hello属性提供的查询结果已重命名为result

    Freemarker模板配置

    此版本更改了Freemarker模板的默认模板文件扩展名。这可以使Spring Boot与Web应用程序的安全配置默认值保持一致。升级时,请将现有模板从重命名*.ftl*.ftlh

    DevTools配置目录

    现在,全局DevTools设置的首选位置是~/.config/spring-boot。可以使用以下任何文件:

    • spring-boot-devtools.properties
    • spring-boot-devtools.yaml
    • spring-boot-devtools.yml

    @ConfigurationPropertiesScan

    @ConfigurationProperties现在可以通过类路径扫描找到带注释的类,以替代使用@EnableConfigurationProperties@Component。添加@ConfigurationPropertiesScan到您的应用程序以启用扫描。

    在Spring Boot 2.2.0中默认启用了配置属性扫描,但是从Spring Boot 2.2.1开始,您必须使用进行选择@ConfigurationPropertiesScan

    @ConstructorBinding

    配置属性现在支持基于构造函数的绑定,该绑定允许带@ConfigurationProperties注释的类不可变。可以通过使用注释一个@ConfigurationProperties类或其构造函数之一来启用基于构造函数的绑定@ConstructorBinding。现在可以在配置属性绑定提供的构造函数参数上使用诸如@DefaultValue和的注释@DateTimeFormat

    Spring Boot 2.2中的弃用

    • logging.file属性已重命名为logging.file.name
    • logging.path属性已重命名为logging.file.path
    • server.connection-timeout不建议使用该属性,而应使用服务器特定的属性,因为它们的行为并不完全相同。
    • server.use-forward-headers不赞成使用该财产server.forward-headers-strategy; 以前server.use-forward-headers=true会使用Web服务器的本机支持。现在,您可以使用实现相同的功能server.forward-headers-strategy=native。由于每个服务器都有特定的行为,因此我们现在提供一种替代方法,该替代方法依赖于Spring的ForwardedHeaderFilterserver.forward-headers-strategy=framework。开发人员应使用最适合其用例的选项。
    • ReactiveWebServerApplicationContext#getWebServerFactory
    • agentMaven插件的属性已重命名为agents
    • 不赞成使用Joda的时间支持java.time
    • ApplicationHealthIndicator赞成的PingHealthIndicator,就是始终贡献。
    • ConfigurationBeanFactoryMetadata赞成ConfigurationPropertiesBean
    • ConfigurationPropertiesBindingPostProcessor赞成@EnableConfigurationPropertiesregister方法的构造函数。
    • ConfigurationPropertiesBindingPostProcessor.VALIDATOR_BEAN_NAME已移至EnableConfigurationProperties.VALIDATOR_BEAN_NAME
    • ConfigurationPropertiesBindingPostProcessorRegistrar赞成@EnableConfigurationProperties
    • WebTestClientBuilderCustomizer已移至org.springframework.boot.test.web.reactive.server

    链接:https://www.jianshu.com/p/c3d00a8e6598

  • 相关阅读:
    复制文字时自动加版权
    Linux安装Docker
    ThreadLocal 理解
    Spring多数据源动态切换
    [LOJ#500]「LibreOJ β Round」ZQC的拼图
    [JLOI2015]装备购买
    「雅礼集训 2017 Day4」洗衣服
    [BJWC2011]元素
    [51nod1577]异或凑数
    [ARC101B]Median of Medians
  • 原文地址:https://www.cnblogs.com/dalianpai/p/11995352.html
Copyright © 2011-2022 走看看