What’s New in Spring?

Dave Syer, 2017

Agenda

  • What’s happening in Spring?
  • How does it all fit together?

Spring Layer Diagram

spring-layers-4

Spring Layers Detail

spring-layers-io-4

Spring Today

November 2017:

  • Reactor: Bismuth-SR4 (reactor-core 3.1.2.RELEASE)
  • Framework: 4.3.12.RELEASE → 5.0.1.RELEASE
  • Security: 4.2.3.RELEASE → 5.0.0.RC1
  • Data: Ingalls-SR8 → Kay-RELEASE
  • Boot: 1.5.8.RELEASE → 2.0.0.M6
  • Cloud: Edgware.RELEASE → Finchley.M4

Spring Layers Detail

spring-layers-io

Spring 5.0

  • Baseline: JDK 8, Servlet 3.1, JMS 2.0, JPA 2.1
  • Performance improvements
  • Functional bean configuration
  • Reactive: WebFlux, Router Functions
  • Support for JUnit 5, JDK 9 and HTTP/2
  • Kotlin

Imperative style (Blocking)

try {
    Person p = personRepository.findById(id);
    handle(p);
} catch	(IOException ex)	{
    error(ex);
}
interface PersonRepository {
     Person findById(String	id);
     List<Person> findAll();
     void save(Person	person);
}

Functional style (Non-blocking)

Mono<Person> p = personRepository.findById(id)
             .map(this::handle)
             .doOnError(this::error);
interface PersonRepository {
     Mono<Person> findById(String id);
     Flux<Person> findAll();
     Mono<Void> save(Person	person);
}

 
 

  • Neutral to Latency
  • Event based

Spring MVC

@GetMapping("/users/{id}")
User getById(@PathVariable String id)	{
    return this.userRepository.findOne(id);
}

Spring WebFlux

@GetMapping("/users/{id}")
Mono<User> getById(@PathVariable String id)	{
    return this.userRepository.findOne(id);
}

Router Function

@Bean
public RouterFunction<?> userEndpoints() {
    return route(GET("/users/{id}"), request ->
        ok().body(
            repository.findOne(request.pathVariable("id")),
            User.class
        ));
}

Spring WebClient

WebClient client = WebClient.create();

Mono<GithubUser> githubUser = client
    .get()
    .uri("https://api.github.com/users/{username}", username)
    .retrieve()
    .bodyToMono(GithubUser.class);

Spring WebClient Scatter Gather

Mono<TwitterUser> twitterUser = client
    .get()
    .uri("https://api.twitter.com/1.1/users/show.json?screen_name={username}", username)
    .retrieve()
    .bodyToMono(TwitterUser.class);

return githubUser.and(twitterUser,
    (github, twitter)-> new AppUser(github, twitter));

Spring WebTestClient

client.get().uri("/users/dave")
    .exchange()
    .expectBody(User.class)
    .consumeWith(result ->
        assertThat(result.getResponseBody().getName())
            .isEqualTo("dave"));
}

N.B. with @SpringBootTest just @AutoConfigureWebTestClient and @Autowired it.

Reactive Spring

More for scalability and stability than for speed

Servlets and Web MVC are not going to go away.

Spring Releases

Project Release Timeline

Reactor

Bismuth

 

Framework

5.0.2.RELEASE

2017Q4

Data

Kay

 

Security

5.0.0.RELEASE

 

Integration

5.0.0.RELEASE

 

…​

 

 

Boot

2.0.0.RELEASE

2018Q1

Cloud

Finchley.RELEASE

 

Spring Cloud

  • Edgware: 2017Q4, Spring Boot 1.5.x
  • Finchley: 2018Q1: Spring Boot 2.0.x

    • Spring Cloud Function
    • Spring Cloud Gateway

/