Skip to content

Whats New in Spring5

Andrew Serff edited this page Dec 22, 2017 · 1 revision

#What's new in Spring 5

SpringOnePlatform 2017

Spring Ecosystem

  • Project Reactor (a Pivotal project, not part of Spring).

Some of the lesser known Spring Projects that we won't cover:

  • Spring Session - makes persistent session management easier. Also distributes sessions across an application.
    • There is a Mongo implementation now...
  • HATEOAS - Self describing RESTful APIs
    • Not really a standard, but one way to describe your API.
  • Spring AMQP - Message Driven framework - RabbitMQ
  • Spring Cloud Data Flow - The Apache NiFi of Spring
    • ETL (Extract->Transform->Load)
    • Built on Spring Integration
    • Deploy to RabbitMQ/Kafka/CloudFoundy to get all the benifits of those platforms like auto scaling of components.
  • Spring Kafka - Similar to AMQP
    • spring-kafka-test Embedded kafka server you can play with
  • Spring Cloud - Umbrella project for many cloud services.
  • Spring Security
    • Spring Social (OAUTH) is migrating into spring security
  • Spring Batch
    • Run applicatin on a schedule.
    • Great for Mainframe downsizing
  • Spring Web Service - Contract-First SOAP
  • Spring Web Flow - Server side control of MVC multi-state interactions
  • Spring Mobile - Extension to MVC to support mobile & non-mobile sites

Spring Framework Updates

AOP And Proxies

Spring Transactions:

  • Will only rollback if you throw a RuntimeException.

Spring Boot uses CGLIB as it's proxy implementation by default.

As of Spring 5, you can how annontate Interfaces or Classes

If you need access to the current proxy: AOPContext.currentProxy()

Others

  • You don't have to Autowire constructors in beans any more
  • You can define beans using Lambdas.
  • @Cacheable(sync)
  • There are a lot of enhancements to JMS including defining POJO to handle JMS. @JMSListener for instance
  • @Nullable / @NotNull - JSR 305
  • Component Scanning Index - Compile time index for component scanning. This should make application startup much faster
  • Spring 5 is Java 8 +
  • Spring 5 has replaced Commons Logging with a bridge module

Discontinued in Spring 5

  • XMLBeans
  • Java Data Objects
  • Guava - use Caffeine
  • Hibernate 3, 4
  • Casper

Spring Web

  • Tiles 2 (only Tiles 3)
  • Portlets
  • Velocity, JasperReports

Lab

New in Spring MVC

Scope

How long your bean hangs around. Scopes are:

  • singleton, prototype, session request, application
  • web-socket, thread, refresh

Thread scope is not something you probably want as all request get their own thread already.

New annotations in 4.3 for web scopes: @SessionScope, @RequestScope

REST Upgrades

  • You can now return a reason with error responses. So you can get a reason why you got a 400 for instance! Return a responseBody with a @ResponseStatus exception handler
  • By default, now every response is a ResponseBody on exception handlers
  • ResponseBodyAdvice will let you get at the data in a restful response before it's converted by the MessageConvertor (to json/xml, etc). You couldn't do this before with the Request Handler Interceptor (preHandle, postHandle).
    • @ControllerAdvice - beforeBodyWrite(...)
  • New Annotation for HTTP method types: @GetMapping, @PostMapping...
  • @GetMapping also responses to HEAD requests automatically. It will run the full reqest though, so if it would be faster to process HEAD requests seperately, you need to implement yourself.
  • @SessionAttribute/@RequestAttribute

Server Push

Part of HTTP2. A response can contain multiple items (css, images, etc). This way you don't have to make multiple requests to get all the initial load.

Spring has a PushBuilder. See slides.

It was asked why you would do this if you were already using CDNs.

New in Spring Boot v2

  • Java 8 + Only
  • JDBCTemplate is thread safe and has new properties
  • DataSource pooling is setup automatically using HikariCP by default.
  • Gradle Support - rewritten. You have to enable dependency-management seperately now.

Actuators

Gives info about your application at runtime. Can use JMX.

  • changed URLs to /application/xxx
  • You must enable the web endoints now: endpoints.default.web.enabled=true
  • Can be secured via spring security now. Just add the endpoints to your security config. See Slide 127.
  • @Endpoint class defines an Actuator.
    • The @Selector becomes a path variable
  • Jolokia support - expose jmx endpoints over http

They use Micrometer on Spring Boot and Cloudfoundy. It's a mertics platform? https://micrometer.io

JUnit 5

Spring 5 has moved to JUnit 5.

2 choices, either your code works, or you throw it away.

Testing shouldn't be optional.

The Mythical Man Month: 9 Women can't have a baby in 1 month.

Junit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage

Must have Java 8. It's all lambdas

Every annotation changed. Make sure you are getting them from org.junit.jupiter

See slides for info on Integration Testing within Spring

No significant changes in Spring Mock MVC, but we should be aware of it.

https://infinitest.github.io/

Clone this wiki locally