Spring Boot 2.0 new features and trends

Source: Internet
Author: User
Tags aop cassandra oauth sessions solr influxdb hazelcast

Using Java 8 as a benchmark

Spring Boot 2.0 requires Java versions to be more than 8, and Java 6 and 7 are no longer supported.

Inline container Package Structure adjustment

In order to support reactive usage scenarios, the built-in container package structure has been refactored a bit larger. Embeddedservletcontainer is renamed to Webserver, and org.springframework.boot.context.embedded The package is redirected to the org.springframework.boot.web.embedded package. For example, if you want to use the Tomcatembeddedservletcontainerfactory callback interface to customize the inline Tomcat container, you should now use Tomcatservletwebserverfactory.

Server Properties Tuning for Servlet-specific

A large number of servlet-exclusive server.* properties were moved to the Server.servlet:

Old property New Property
server.context-parameters.* server.servlet.context-parameters.*
server.context-path server.servlet.context-path
server.jsp.class-name server.servlet.jsp.class-name
server.jsp.init-parameters.* server.servlet.jsp.init-parameters.*
server.jsp.registered server.servlet.jsp.registered
server.servlet-path server.servlet.path

It can be seen that the server is no longer the only servlet, there are others to join.

Actuator Default Mappings

The actuator endpoint (endpoint) is now mapped to/application by default, for example, the/info endpoint is now in/application/info. However, you can use Management.context-path to override this default value.

@ConditionalOnBean

@ConditionalOnBean the current judging conditions are changed from or to and.

Remote CRaSH Shell

At 1.5, when this remote tool is marked as deprecated,2.0, the support will be removed completely and items based on this feature will be deleted.

Spring loaded no longer supports

Spring loaded is no longer supported because the spring loaded project has been moved to attic. It is now advisable to use Devtools. Spring loaded no longer supports it.

Hazelcast automatic configuration no longer supported

Hazelcastinstance can no longer be automatically configured for caching. Therefore, the Spring.cache.hazelcast.config property is no longer available.

The default connection pool changes

The default connection pool has been switched from Tomcat to HIKARICP. If you used to use Spring.datasource.type to force Hikari in a tomcat-based application, you can now delete this overlay. Similarly, if you want to use Tomcat's connection pool, simply add the following configuration:

Spring.datasource.type=org.apache.tomcat.jdbc.pool.datasource

Servlet Filters

The default dispatcher type for a filter is now dipatchertype.request, which ensures that the default configuration of spring boot and servlet is unified.

Spring Security

Spring Security's filter can now be automatically configured with the following types: ASYNC, ERROR, and REQUEST. This leaves the configuration in spring boot consistent with the spring security default configuration.

Spring Session

The filter for Spring session now supports automatic configuration of the following dispatcher types ASYNC, ERROR, and REQUEST. The same is done to keep the spring boot configuration consistent with the default configuration of the spring session. It is important to note that MONGO and GemFire will no longer be supported from Spring Session 2.0.

Jetty

Required jetty minimum version is 9.4.

Tomcat

Tomcat Minimum version 8.5 is required.

Hibernate

Hibernate minimum required version is 5.2.

Gradle

Required Gradle minimum version is 3.4.

SendGrid

The minimum supported version of SendGrid is 3.2. To support this upgrade, username and password have been killed. Because API key is now the only supported authentication method.

The change of Starter's transfer dependence

Several spring Boot starter were previously passed by spring MVC and Spring-boot-starter-web. To support the spring Webflux, Spring-boot-starter-mustache and spring-boot-starter-thymeleaf no longer rely on spring-boot-starter-web. Now you have to choose and add Spring-boot-starter-web or Spring-boot-starter-webflux as a dependency.

Remember: The Web and Webflux are parallel relationships. We mentioned spring Webflux in our previous article. You can see: Spring 5 Adds a new reactive web framework: Webflux.

SOLR Health indicators

The health check information for SOLR is no longer the Solrstatus attribute. Now is the Status property, which is a standard state attribute that corresponds to an integer value of one.

Default Proxy Policy

Spring boot now defaults to using the Cglib Proxy and includes AOP support. If you need agent-based agent (proxy-based) policy, you need to spring.aop.proxy-target-class set the setting to False.

CLI-based testing

Removing test support from the Spring boot CLI, it is now recommended that you build applications using MAVEN or Gradle to use the rich test support they provide.

@ConfigurationProperties

@ConfigurationPropertiesThe Ignorenestedproperties property has been deleted.

Multipart configuration changes

In order to better reflect the characteristics of the servlet, Spring.http.multipart. The property has been named Spring.servlet.multipart.

PS: In fact, it is because Webflux came, only to distinguish between Servlets and Webflux.

Mustache template Default file name extension

In the past, the default file name extension for mustache templates is. html. Now. Mustache has become an officially designated extension, and many IDE plugins already support this suffix. You can overwrite the default support now by Spring.mustache.suffix.

Spring Framework 5.0

Spring Boot 2.0 is built on top of the spring Framework 5.0 (minimum requirements). The biggest highlight of Spring 5 is the reactive. You can take a look at this: Spring 5 adds a new reactive web framework: Webflux.

Untie Improvement

The loosening has been improved. Here's a simple example:

A simple property is bound after the special character is removed and then converted to lowercase. Like what:

The following properties will eventually be mapped to Spring.jpa.databaseplatform=mysql:

Spring.jpa.database-platform=mysql

Spring.jpa.databaseplatform=mysql

Spring. Jpa.database_platform=mysql

For more information, we can refer to: https://github.com/spring-projects/spring-boot/wiki/Relaxed-Binding-2.0

Webflux and Webflux.fn Support

Spring Boot 2.0 provides a new starter to support reactive Spring Web frameworks. The starter is Spring-boot-starter-webflux. Where reactor Netty is the default Web engine (Spring-boot-starter-reactor-netty).

Reactive database Support

Spring Boot 2.0 pairs the database with support for automatic configuration (auto-configuration) reactive:

    • MongoDB (spring-boot-starter-data-mongodb-reactive)
    • Redis (spring-boot-starter-data-redis-reactive)
    • Cassandra (spring-boot-starter-data-cassandra-reactive)

@DataMongoTestTest annotations are also supported for reactive.

@WebFluxTest Support

Reactive controller can now be used @WebFluxTest to test. It provides functionality and is @WebMvcTest similar. And webtestclient can be used directly, has been automatically configured (auto-configured).

Supports automatic configuration with @springboottest webtestclient

When you use @SpringBootTest the with an actual server (which is, either Defined_port or Random_port), a webtestclient is available the same the T Estresttemplate is.

Using @springboottest for webtestclient automatic configuration

When you use @springboottest for an actual server (that is, defined_port or random_port), Webtestclient is available in the same way as testresttemplate.

Gradle Plug-in

Spring Boot's Gradle plugin has been largely rewritten to achieve some significant improvements. In this regard is not detailed, the interested students can go to explore.

Status code change for/loggers endpoint Post

The status code for the post operation on the/loggers endpoint has been changed from 200 to 204.

Elasticsearch

Elasticsearch has been upgraded to 5.4. As with elastic's announcement that no longer supports embedded elasticsearch, Nodeclient's automatic configuration has been removed. This is the same rhythm. You can now automatically configure transportclient by using Spring.data.elasticsearch.cluster-nodes, where the value can be the address of one or more nodes to connect to.

Quartz Scheduler

Spring Boot 2 provides support for the Quartz scheduler. You can join Spring-boot-starter-quartz starter to enable. and supports memory-based and JDBC-based two storage.

Spring Data Web Configuration

Spring Boot exposes a new Spring.data.web configuration namespace that can be easily configured for paging and sorting.

Json Starter

A new Spring-boot-starter-json starter aggregates a number of commonly used JSON tools to support the reading and writing of JSON.

It provides not only jackson-databind but also useful modules when you use JAVA8: Jackson-datatype-jdk8, jackson-datatype-jsr310, and Jackson-module-parameter-names.

This new starter can be used where jackson-databind is used before.

Thymeleaf Starter

Thymeleaf starter now contains Thymeleaf-extras-java8time, which is available out of the box.

InfluxDB

If the Influxdb Java client and the Spring.influx.url are set, a INFLUXDB client is now automatically configured. And now it supports certification.

JdbcTemplate

Spring boot autoconfiguration (auto-configuration) JdbcTemplate can now be customized with the Spring.jdbc.template namespace. In addition, the namedparameterjdbctemplate of the automatic configuration (auto-configuration) is jdbctemplate at the bottom.

Jooq

Spring boot can now automatically detect Jooq dialects (similar to the JPA dialect) based on DataSource.

In addition, @jooqtest is introduced to test scenarios where only Jooq can hold.

@DataRedisTest

A new note for Redis was added to the test.

Powerful MONGO client-side customization

It is now possible to highly customize the spring boot MONGO client by Mongoclientsettingsbuildercustomizer this bean.

Cassandra

Spring.data.cassandra now supports pooling (pooling).

Kafka Listener supports bulk consumption

Now support one-time bulk consumption of multiple consumerrecord, you can create a batch of listeners (listener), so set:

Spring.kafka.listener.type=batch

Web Filters Initialization

The Web filters is now initialized immediately in all supported containers. That is eagerly, urgent loading.

Auto-configuration Report

Classes that do not meet the conditions now (unconditional) are also included and returned in response of the actuator endpoint of the automatic configuration (auto-configuration).

Resetting the logger operation

The loggers endpoint (endpoint) now supports the reset log level to the default settings.

Maven Plugin Properties

Plug-in configuration properties are now exposed differently, and all are now prefixed with spring-boot, in order to avoid conflicts with other plugins causing errors.

For example, the following command line can enable profile Foo:

MVN Spring-boot:run-dspring-boot.run.profiles=foo

Devtools Remote Debugging

Support for remote debugging over HTTP has been removed from Devtools. (#9489)

Jetty

In order to be on par with Tomcat and undertow, all HTTP method jetty are now compressed, rather than just compressing the GET request (#8184).

Reactive server Customization

When configuring a reactive Web server, the customizer for Jetty,tomcat,undertow is now called (#9572).

Jolokia

Jolokia is no longer a endpoint. and is disabled by default, which has persisted with the other web endpoints. Its configuration has been transferred to the Management.jolokia. If you want to enable Jolokia, you can add management.jolokia.enabled=true to your configuration.

Database migration

The key configured by Liquibase and Flyway has been moved to the Spring namespace: (for example: Spring.liquibase and Spring.flyway).

Auto-configuration sort

The @AutoConfigureOrder default value is changed from Ordered.lowest_precedence to 0. (#10142)

Auto-configuration Test Tools

A new Applicationcontextrunner test tool makes it easy to test the automatic configuration. In the future, all test suites will be migrated to this model.

Java 9 Support

Basic support for Java 9. The reason is "basic", because the user has not yet been verified.

Jedis into lettuce.

The Redis client driver is now changed from Jedis to lettuce. The students who use Jedis probably know the direction.

But still support Jedis, then exclude off Io.lettuce:lettuce-core, then add Redis.clients:jedis just.

OAuth 2.0 Support

The functionality in the Spring Security OAuth project will be migrated to spring security. will be OAuth 2.0.

Mockito 1.x

Mockito 1.x no longer supports @mockbean and @spybean. If you do not use spring-boot-starter-test to manage dependencies, you should upgrade to Mockito 2.x.

Json-b Support

In addition to Jackson and Gson, Json-b is now supported. JSON test support has also been updated to the new Jsonbtester class.

Session Endpoint

Spring session can now be used to find and delete sessions by/application/sessions actuator endpoint.

Configurationproperties Verification

If you want to @ConfigurationProperties enable validation on an object, you just need to add @Validated it.

Spring Mobile

Automatic configuration and dependencies for spring Mobile are no longer supported and have been removed. Khan, we've also covered this project in previous articles: using spring boot to develop a spring mobile program.

Spring Webflux Support Error Convention

Spring boot now makes Webflux's error conventions consistent with MVC, just like MVC: default views and JSON response errors, custom error views, and so on.

TLS Configuration and HTTP/2 support

You can now configure SSL for your Webflux app, using server.ssl.* configuration properties. Tomcat, Jetty, Undertow and Reactor Netty all support.

You can now also configure HTTP/2 for your MVC or Webflux app:

Use server.http2.enabled .

@KafkaListener support the use of @sendto

Kafka Listener, which uses the automatic configuration factory, is now supported @SendTo .

Kotlin extension

Spring Boot 2.0 released the Kotlin runapplication extension:

    1. Package Com.example.demo
    2. Import Org.springframework.boot.autoconfigure.SpringBootApplication
    3. Import Org.springframework.boot.runApplication
    4. @SpringBootApplication
    5. class demoapplication
    6. Fun Main (args: array<string>) {
    7. Runapplication<demoapplication> (*args)
    8. }

Job Command line Runner order

Commandlinerunner now executes the batch job with a start order of 0.

Templated welcome page with automatic configuration support

Spring Boot 2.0 now supports both static and templated types of welcome pages. It will first go to the configuration of the static content of the directory to find the index.html file, if not found, and then go to find the index template. Once you find one, you will be used as a welcome page.

Context path will be printed at startup

In the previous version of Spring boot, the context path seemed to be less important than that. Now when we use the inline container, the context path is printed next to the HTTP port, like this:

Tomcat started on port (s): 8080 (HTTP) with context path '/foo '

Test optimization, automatic scanning of converter and genericconverter

Converter and Genericconverter beans can now be automatically scanned by @webmvctest and @webfluxtest.

Health vs. Status

Status endpoint has been removed and is now changed to health. This health endpoint can show both status and more detail. The health endpoint is now exposed by default (show status only). If you want to show more details, you can do this by modifying the attribute Management.endpoints.health.show-details:

Management.endpoints.health.show-details=true

Original link:

Https://mp.weixin.qq.com/s/EWmuzsgHueHcSB0WH-3AQw

Spring Boot 2.0 new features and development direction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.