SlideShare a Scribd company logo
1 of 38
Download to read offline
© Copyright 2017 Pivotal Software, Inc. All rights Reserved. Version 1.0
Jay Lee(jaylee@pivotal.io)
November 2017
Spring 5 New Features
Spring 5 Major Changes
● Java 9 Compatible
● JavaEE8 Support
● HTTP/2 Support
● Reactive: WebFlux, Router Functions
● Functional Bean Configuration
● JUnit 5
● Portlet Deprecated
Baseline Changes
Version Upgrades introduced in Spring 5
●JDK 8+
●Servlet 3.1+
●JMS 2.0
●JPA 2.1
●JavaEE7+
Baseline Changes – Java9 Jigsaw
SPR-13501: Declare Spring modules with JDK 9 module metadata is
still Open
Manifest-Version: 1.0
Implementation-Title: spring-core
Automatic-Module-Name: spring.core
Implementation-Version: 5.0.2.BUILD-SNAPSHOT
Created-By: 1.8.0_144 (Oracle Corporation)
JavaEE 8 GA – Sep 21, 2017
● CDI 2.0 (JSR 365)
● JSON-B 1.0 (JSR 367)
● Servlet 4.0 (JSR 369)
● JAX-RS 2.1 (JSR 370)
● JSF 2.3 (JSR 372)
● JSON-P 1.1 (JSR 374)
● Security 1.0 (JSR 375)
● Bean Validation 2.0 (JSR 380)
● JPA 2.2 - Maintenance Release
Java API for JSON Binding (JSON-B) 1.0 – JSR 367
Standard Binding Layer for converting Java objects to/from JSON
● Thread Safe
● Apache Johnzon
● Eclipse Yasson
Java API for JSON Binding (JSON-B) 1.0 – JSR 367
Person person = new Person();
person.name = ”Jay Lee";
person.age = 1;
person.email = “jaylee@pivotal.io”;
Jsonb jsonb = JsonbBuilder.create();
String JsonToString = jsonb.toJson(person);
System.out.println(JsonToString );
person = jsonb.fromJson("{"name":”Jay
Lee","age":1,”email":”jaylee@pivotal.io"}", Person.class);
Java API for JSON Binding (JSON-B) 1.0 – JSR 367
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-json_1.1_spec</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-jsonb</artifactId>
<version>1.1.5</version>
</dependency>
Java API for JSON Binding (JSON-B) 1.0 – JSR 367
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>org.eclipse</groupId>
<artifactId>yasson</artifactId>
<version>1.0.1</version>
</dependency>
Java API for JSON Binding (JSON-B) 1.0 – JSR 367
New HttpMessageConverter for JSON-B in Spring5
@Bean
public HttpMessageConverters customConverters() {
Collection<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
JsonbHttpMessageConverter jsonbHttpMessageConverter = new JsonbHttpMessageConverter();
messageConverters.add(jsonbHttpMessageConverter);
return new HttpMessageConverters(true, messageConverters);
}
Servlet 4.0 – Server Push
Server pushes resources to Clients, efficient way to transfer
resources using HTTP/2
@GetMapping("/pushbuilder")
public String getPage(PushBuilder builder) {
builder.path("/scripts.js").push();
builder.path("/styles.css").push();
return "index";
}
Servlet 4.0 – HttpServletMapping
Provide Runtime Discovery of URL Mappings
@GetMapping("/servlet4")
public void index(final HttpServletRequest request) {
HttpServletMapping mapping =
request.getHttpServletMapping();
System.out.println(mapping.getServletName());
System.out.println(mapping.getPattern());
System.out.println(mapping.getMappingMatch().name());
System.out.println(mapping.getMatchValue());
}
Bean Validation 2.0 – JSR 380
1.1 was introduced in 2013, lacking of supports for new Java8, 9.
● New JDK Types Including LocalTime, Optional and etc
● Lambda
● Type Annocation
● @Email, @Positive, @PositiveOrZero, @Negative, @NegativeOrZero,
@PastOrPresent, @FutureOrPresent, @NotEmpty, and @NotBlank.
Spring 5 Major Changes
● Logging Enhancement
● Performance Enhancement
● Functional Bean Configuration
● JSR 305
● Spring MVC - HTTP/2 Support,
● Reactive: WebFlux, Router Functions
● JUnit 5
Spring 5 – XML Configuration Changes
Streamlined to use unversioned Schema
Spring 5 - Logging Enhancement
spring-jcl replaces Commons Logging by default
● Autodetecting Log4j 2.x, SLF4J, and JUL (java.util.logging) by Class
Loading
Spring 5 - Logging Enhancement
Spring 5 - Component Scanning Enhancement
Component scanning time reduced by index, improving Start Up Time
• META-INF/spring.components is created at Compile Time
• @Indexed Annotation
• org.springframework.context.index.CandidateComponentsIndex
• -Dspring.index.ignore=true to fall back to old mechanism
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Component {
String value() default "";
}
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Indexed
public @interface Component {
String value() default "";
}
Spring 5 - Component Scanning Enhancement
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-indexer</artifactId>
<optional>true</optional>
</dependency>
Spring 5 - Component Scanning Enhancement
• JMH Result, ClassPath Scanning versus Index Scanning
• Noticeable Differences in having more classes
https://github.com/snicoll-scratches/test-spring-components-index
Spring 5 - Functional Bean Configuration
Support for Functional Bean Registration in GenericApplicationContext,
AnnotationConfigApplicationContext
● Very efficient, no reflection, no CGLIB proxies involved
● Lambda with Supplier act as a FactoryBean
Spring 5 - Functional Bean Configuration
@Autowired
GenericApplicationContext ctx;
@Test
public void functionalBeanTest() {
ctx.registerBean(Person.class, () -> new Person());
ctx.registerBean("personService", Person.class,
() -> new Person(), bd -> bd.setAutowireCandidate(false));
ctx.registerBean(”carService", Car.class,
() -> new Car(), bd ->
bd.setScope(BeanDefinition.SCOPE_PROTOTYPE));
}
Spring 5 – JSR 305
SPR-15540 Introduce null-safety of Spring Framework API
• Becomes Kotlin Friendly (-Xjsr305=strict as of 1.1.51)
https://github.com/spring-projects/spring-framework/commit/f813712f5b413b354560cd7cc006352e9defa9a3
Spring 5 – JSR 305 Nullable
New Annotation org.springframework.lang.NonNull,
org.springframework.lang.Nullable leverages JSR 305
@Target({ElementType.METHOD, ElementType.PARAMETER,
ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Nonnull
@TypeQualifierNickname
public @interface NonNull {
}
Spring 5 – Spring MVC
HTTP/2 and Servlet 4.0
• PushBuilder
• WebFlux
• Support Reactor 3.1, RxJava 1.3, 2.1 as return values
• JSON BINDING API
• Jackson 2.9
• Protobuf 3.0
• URL Matching
Spring 5 – HTTP/2(Servlet 4.0) Supported Containers
● Tomcat 9.0
● Jetty 9.3
● Undertow 1.4
ex. Spring Boot
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-juli</artifactId>
<version>9.0.1</version>
</dependency>
Spring 5 MVC – Multipart File Size
MaxUploadSizeExceededException will be thrown for multipart size
overrun
• Default Value
• Two Properties(Default Value)
• spring.servlet.multipart.max-file-size=1MB
spring.servlet.multipart.max-request-size=10MB
Spring 5 MVC – URL Matcher changed
PathPatternParser is alternative to Traditional AntPathMatcher for
URL Matching
• org.springframework.web.util.patterns.PathPattern
Examples:
/pages/t?st.html —/pages/test.html, /pages/tast.html /pages/toast.html
/resources/*.png — matches all .png files in the resources directory
/resources/** — matches all files underneath the /resources/ path,
including /resources/image.png and /resources/css/spring.css
/resources/{*path} — matches all files underneath the /resources/ path and captures their relative
path in a variable named "path"; /resources/image.png will match with ”path" -> "/image.png",
and /resources/css/spring.css will match with ”path" -> "/css/spring.css"
/resources/{filename:w+}.dat will match /resources/spring.dat and assign the value "spring" to
the filename variable
Spring 5 MVC – Throwing Exception from Controller
ResponseStatusException is Introduced to throw Exception in MVC
• SPR-14895:Allow HTTP status exceptions to be easily thrown from
Controllers
• ResponseEntity(HttpStatus.BAD_REQUEST)?
@GetMapping ( "/throw" )
public void getException () {
throw new ResponseStatusException( HttpStatus. BAD_REQUEST
, "request invalid." );
}
Spring 5 WebFlux – WebClient
Reactive Web Client introduced in Spring 5, alternative to
RestTemplate
● AsyncRestTemplate is deprecated
WebClient client= WebClient.create();
Mono<Person> person=client
.get()
.uri("http://jay-person.cfapps.io/{name}",name)
.retrieve()
.bodyToMono(Person.class);
Spring 5 WebFlux –WebTestClient
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureWebTestClient
public class MicrometerApplicationTests {
@Autowired
WebTestClient client;
@Test
public void testWebClient() {
client.get().uri("/person/Jay")
.exchange()
.expectBody(Person.class)
.consumeWith(result ->
assertThat(result.getResponseBody().getName()).isEqualTo("Jay Lee"));
}
Spring 5 WebFlux – Server
RouterFunction is introduced for functional programming
RouterFunction<?> route = route(GET("/users"), request ->
ok().body(repository.findAll(), Person.class))
.andRoute(GET("/users/{id}"), request ->
ok().body(repository.findOne(request.pathVariable("id")),
Person.class))
.andRoute(POST("/users"), request ->
ok().build(repository.save(request.bodyToMono(Person.class)).then())
);
Spring Boot and Cloud
Spring Boot 2.0 will be GA in Feb 2018
● Spring Cloud Finchley Release Train based on Spring Boot 2.0
● Spring Cloud Gateway
● Spring Cloud Function
Spring Release Calendar
https://spring-calendar.cfapps.io/
Spring 5 – JUnit 5 Jupiter Support
Complete Support provided for Jupiter APIs
• @SpringJUnitConfig
• @SpringJUnitWebConfig
• @EnabledIf
• @DisabledIf
• Parallel Test Execution Support
Spring 5 – JUnit 5 Jupiter Support
@SpringJUnitConfig(TestConfiguration.class)
public class MicrometerApplicationTests {
@EnabledIf(expression = "${tests.enabled}", loadContext = true)
@Test
void givenEnabledIfExpression_WhenTrue_ThenTestExecuted() {
assertTrue(true);
}
@EnabledIf("#{systemProperties['java.version'].startsWith('1.8')}")
@Test
void givenEnabledIfSpel_WhenTrue_ThenTestExecuted() {
assertTrue(true);
}
}
Spring 5 – Deprecated APIs
HTTP/2 and Servlet 4.0
• Hibernate 3, 4
• Portlet
• Velocity
• JasperReports
• XMLBeans
• JDO
• Guava
Transforming How The World Builds Software
© Copyright 2017 Pivotal Software, Inc. All rights Reserved.

More Related Content

What's hot

Whats New in MSBuild 3.5 and Team Build 2008
Whats New in MSBuild 3.5 and Team Build 2008Whats New in MSBuild 3.5 and Team Build 2008
Whats New in MSBuild 3.5 and Team Build 2008
wbarthol
 

What's hot (20)

rx-java-presentation
rx-java-presentationrx-java-presentation
rx-java-presentation
 
Dropwizard
DropwizardDropwizard
Dropwizard
 
Introduction to Retrofit and RxJava
Introduction to Retrofit and RxJavaIntroduction to Retrofit and RxJava
Introduction to Retrofit and RxJava
 
Supercharged java 8 : with cyclops-react
Supercharged java 8 : with cyclops-reactSupercharged java 8 : with cyclops-react
Supercharged java 8 : with cyclops-react
 
Gradle - Build System
Gradle - Build SystemGradle - Build System
Gradle - Build System
 
FlutterでGraphQLを扱う
FlutterでGraphQLを扱うFlutterでGraphQLを扱う
FlutterでGraphQLを扱う
 
Reactive Applications with Apache Pulsar and Spring Boot
Reactive Applications with Apache Pulsar and Spring BootReactive Applications with Apache Pulsar and Spring Boot
Reactive Applications with Apache Pulsar and Spring Boot
 
Clean Architecture on Android
Clean Architecture on AndroidClean Architecture on Android
Clean Architecture on Android
 
Database migration with flyway
Database migration  with flywayDatabase migration  with flyway
Database migration with flyway
 
Dropwizard Internals
Dropwizard InternalsDropwizard Internals
Dropwizard Internals
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJava
 
Reactors.io
Reactors.ioReactors.io
Reactors.io
 
Take Control of your Integration Testing with TestContainers
Take Control of your Integration Testing with TestContainersTake Control of your Integration Testing with TestContainers
Take Control of your Integration Testing with TestContainers
 
Whats New in MSBuild 3.5 and Team Build 2008
Whats New in MSBuild 3.5 and Team Build 2008Whats New in MSBuild 3.5 and Team Build 2008
Whats New in MSBuild 3.5 and Team Build 2008
 
What’s expected in Spring 5
What’s expected in Spring 5What’s expected in Spring 5
What’s expected in Spring 5
 
Towards Safe Refactoring for Intelligent Parallelization of Java 8 Streams
Towards Safe Refactoring for Intelligent Parallelization of Java 8 StreamsTowards Safe Refactoring for Intelligent Parallelization of Java 8 Streams
Towards Safe Refactoring for Intelligent Parallelization of Java 8 Streams
 
Javantura v3 - Going Reactive with RxJava – Hrvoje Crnjak
Javantura v3 - Going Reactive with RxJava – Hrvoje CrnjakJavantura v3 - Going Reactive with RxJava – Hrvoje Crnjak
Javantura v3 - Going Reactive with RxJava – Hrvoje Crnjak
 
Bulding a reactive game engine with Spring 5 & Couchbase
Bulding a reactive game engine with Spring 5 & CouchbaseBulding a reactive game engine with Spring 5 & Couchbase
Bulding a reactive game engine with Spring 5 & Couchbase
 
Introduction to Scala Macros
Introduction to Scala MacrosIntroduction to Scala Macros
Introduction to Scala Macros
 
12 Factor App: Best Practices for JVM Deployment
12 Factor App: Best Practices for JVM Deployment12 Factor App: Best Practices for JVM Deployment
12 Factor App: Best Practices for JVM Deployment
 

Similar to Spring5 New Features

Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5
Tuna Tore
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892
Tuna Tore
 
Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)
Gunith Devasurendra
 
Spring design-juergen-qcon
Spring design-juergen-qconSpring design-juergen-qcon
Spring design-juergen-qcon
Yiwei Ma
 

Similar to Spring5 New Features (20)

Spring5 New Features - Nov, 2017
Spring5 New Features - Nov, 2017Spring5 New Features - Nov, 2017
Spring5 New Features - Nov, 2017
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892
 
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdfdokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
 
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
dokumen.tips_rediscovering-spring-with-spring-boot1.pdfdokumen.tips_rediscovering-spring-with-spring-boot1.pdf
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
 
Multi Client Development with Spring
Multi Client Development with SpringMulti Client Development with Spring
Multi Client Development with Spring
 
Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)
 
Introducing Spring Framework 5.3
Introducing Spring Framework 5.3Introducing Spring Framework 5.3
Introducing Spring Framework 5.3
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API's
 
SpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptxSpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptx
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
Angular beans
Angular beansAngular beans
Angular beans
 
Spring design-juergen-qcon
Spring design-juergen-qconSpring design-juergen-qcon
Spring design-juergen-qcon
 
Java servlet technology
Java servlet technologyJava servlet technology
Java servlet technology
 
C#on linux
C#on linuxC#on linux
C#on linux
 
Springboot2 postgresql-jpa-hibernate-crud-example with test
Springboot2 postgresql-jpa-hibernate-crud-example with testSpringboot2 postgresql-jpa-hibernate-crud-example with test
Springboot2 postgresql-jpa-hibernate-crud-example with test
 
Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6
 
Integrating Wicket with Java EE 6
Integrating Wicket with Java EE 6Integrating Wicket with Java EE 6
Integrating Wicket with Java EE 6
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 

More from Jay Lee (10)

Spring on Kubernetes
Spring on KubernetesSpring on Kubernetes
Spring on Kubernetes
 
Knative And Pivotal Function As a Service
Knative And Pivotal Function As a ServiceKnative And Pivotal Function As a Service
Knative And Pivotal Function As a Service
 
Knative and Riff
Knative and RiffKnative and Riff
Knative and Riff
 
CF Korea Meetup - Spring Cloud Services
CF Korea Meetup - Spring Cloud ServicesCF Korea Meetup - Spring Cloud Services
CF Korea Meetup - Spring Cloud Services
 
SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire
SpringCamp 2016 - Apache Geode 와 Spring Data GemfireSpringCamp 2016 - Apache Geode 와 Spring Data Gemfire
SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire
 
CF Korea Meetup - Gemfire on PCF
CF Korea Meetup - Gemfire on PCF CF Korea Meetup - Gemfire on PCF
CF Korea Meetup - Gemfire on PCF
 
JavaEE6 - 설계 차원의 단순성
JavaEE6 - 설계 차원의 단순성JavaEE6 - 설계 차원의 단순성
JavaEE6 - 설계 차원의 단순성
 
Java8 - Oracle Korea Magazine
Java8 - Oracle Korea MagazineJava8 - Oracle Korea Magazine
Java8 - Oracle Korea Magazine
 
Java EE7
Java EE7Java EE7
Java EE7
 
Java 8 & Beyond
Java 8 & BeyondJava 8 & Beyond
Java 8 & Beyond
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 

Spring5 New Features

  • 1. © Copyright 2017 Pivotal Software, Inc. All rights Reserved. Version 1.0 Jay Lee(jaylee@pivotal.io) November 2017 Spring 5 New Features
  • 2. Spring 5 Major Changes ● Java 9 Compatible ● JavaEE8 Support ● HTTP/2 Support ● Reactive: WebFlux, Router Functions ● Functional Bean Configuration ● JUnit 5 ● Portlet Deprecated
  • 3. Baseline Changes Version Upgrades introduced in Spring 5 ●JDK 8+ ●Servlet 3.1+ ●JMS 2.0 ●JPA 2.1 ●JavaEE7+
  • 4. Baseline Changes – Java9 Jigsaw SPR-13501: Declare Spring modules with JDK 9 module metadata is still Open Manifest-Version: 1.0 Implementation-Title: spring-core Automatic-Module-Name: spring.core Implementation-Version: 5.0.2.BUILD-SNAPSHOT Created-By: 1.8.0_144 (Oracle Corporation)
  • 5. JavaEE 8 GA – Sep 21, 2017 ● CDI 2.0 (JSR 365) ● JSON-B 1.0 (JSR 367) ● Servlet 4.0 (JSR 369) ● JAX-RS 2.1 (JSR 370) ● JSF 2.3 (JSR 372) ● JSON-P 1.1 (JSR 374) ● Security 1.0 (JSR 375) ● Bean Validation 2.0 (JSR 380) ● JPA 2.2 - Maintenance Release
  • 6. Java API for JSON Binding (JSON-B) 1.0 – JSR 367 Standard Binding Layer for converting Java objects to/from JSON ● Thread Safe ● Apache Johnzon ● Eclipse Yasson
  • 7. Java API for JSON Binding (JSON-B) 1.0 – JSR 367 Person person = new Person(); person.name = ”Jay Lee"; person.age = 1; person.email = “jaylee@pivotal.io”; Jsonb jsonb = JsonbBuilder.create(); String JsonToString = jsonb.toJson(person); System.out.println(JsonToString ); person = jsonb.fromJson("{"name":”Jay Lee","age":1,”email":”jaylee@pivotal.io"}", Person.class);
  • 8. Java API for JSON Binding (JSON-B) 1.0 – JSR 367 <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-json_1.1_spec</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>org.apache.johnzon</groupId> <artifactId>johnzon-jsonb</artifactId> <version>1.1.5</version> </dependency>
  • 9. Java API for JSON Binding (JSON-B) 1.0 – JSR 367 <dependency> <groupId>org.glassfish</groupId> <artifactId>javax.json</artifactId> <version>1.1.2</version> </dependency> <dependency> <groupId>org.eclipse</groupId> <artifactId>yasson</artifactId> <version>1.0.1</version> </dependency>
  • 10. Java API for JSON Binding (JSON-B) 1.0 – JSR 367 New HttpMessageConverter for JSON-B in Spring5 @Bean public HttpMessageConverters customConverters() { Collection<HttpMessageConverter<?>> messageConverters = new ArrayList<>(); JsonbHttpMessageConverter jsonbHttpMessageConverter = new JsonbHttpMessageConverter(); messageConverters.add(jsonbHttpMessageConverter); return new HttpMessageConverters(true, messageConverters); }
  • 11. Servlet 4.0 – Server Push Server pushes resources to Clients, efficient way to transfer resources using HTTP/2 @GetMapping("/pushbuilder") public String getPage(PushBuilder builder) { builder.path("/scripts.js").push(); builder.path("/styles.css").push(); return "index"; }
  • 12. Servlet 4.0 – HttpServletMapping Provide Runtime Discovery of URL Mappings @GetMapping("/servlet4") public void index(final HttpServletRequest request) { HttpServletMapping mapping = request.getHttpServletMapping(); System.out.println(mapping.getServletName()); System.out.println(mapping.getPattern()); System.out.println(mapping.getMappingMatch().name()); System.out.println(mapping.getMatchValue()); }
  • 13. Bean Validation 2.0 – JSR 380 1.1 was introduced in 2013, lacking of supports for new Java8, 9. ● New JDK Types Including LocalTime, Optional and etc ● Lambda ● Type Annocation ● @Email, @Positive, @PositiveOrZero, @Negative, @NegativeOrZero, @PastOrPresent, @FutureOrPresent, @NotEmpty, and @NotBlank.
  • 14. Spring 5 Major Changes ● Logging Enhancement ● Performance Enhancement ● Functional Bean Configuration ● JSR 305 ● Spring MVC - HTTP/2 Support, ● Reactive: WebFlux, Router Functions ● JUnit 5
  • 15. Spring 5 – XML Configuration Changes Streamlined to use unversioned Schema
  • 16. Spring 5 - Logging Enhancement spring-jcl replaces Commons Logging by default ● Autodetecting Log4j 2.x, SLF4J, and JUL (java.util.logging) by Class Loading
  • 17. Spring 5 - Logging Enhancement
  • 18. Spring 5 - Component Scanning Enhancement Component scanning time reduced by index, improving Start Up Time • META-INF/spring.components is created at Compile Time • @Indexed Annotation • org.springframework.context.index.CandidateComponentsIndex • -Dspring.index.ignore=true to fall back to old mechanism @Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface Component { String value() default ""; } @Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented @Indexed public @interface Component { String value() default ""; }
  • 19. Spring 5 - Component Scanning Enhancement <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-indexer</artifactId> <optional>true</optional> </dependency>
  • 20. Spring 5 - Component Scanning Enhancement • JMH Result, ClassPath Scanning versus Index Scanning • Noticeable Differences in having more classes https://github.com/snicoll-scratches/test-spring-components-index
  • 21. Spring 5 - Functional Bean Configuration Support for Functional Bean Registration in GenericApplicationContext, AnnotationConfigApplicationContext ● Very efficient, no reflection, no CGLIB proxies involved ● Lambda with Supplier act as a FactoryBean
  • 22. Spring 5 - Functional Bean Configuration @Autowired GenericApplicationContext ctx; @Test public void functionalBeanTest() { ctx.registerBean(Person.class, () -> new Person()); ctx.registerBean("personService", Person.class, () -> new Person(), bd -> bd.setAutowireCandidate(false)); ctx.registerBean(”carService", Car.class, () -> new Car(), bd -> bd.setScope(BeanDefinition.SCOPE_PROTOTYPE)); }
  • 23. Spring 5 – JSR 305 SPR-15540 Introduce null-safety of Spring Framework API • Becomes Kotlin Friendly (-Xjsr305=strict as of 1.1.51) https://github.com/spring-projects/spring-framework/commit/f813712f5b413b354560cd7cc006352e9defa9a3
  • 24. Spring 5 – JSR 305 Nullable New Annotation org.springframework.lang.NonNull, org.springframework.lang.Nullable leverages JSR 305 @Target({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @Documented @Nonnull @TypeQualifierNickname public @interface NonNull { }
  • 25. Spring 5 – Spring MVC HTTP/2 and Servlet 4.0 • PushBuilder • WebFlux • Support Reactor 3.1, RxJava 1.3, 2.1 as return values • JSON BINDING API • Jackson 2.9 • Protobuf 3.0 • URL Matching
  • 26. Spring 5 – HTTP/2(Servlet 4.0) Supported Containers ● Tomcat 9.0 ● Jetty 9.3 ● Undertow 1.4 ex. Spring Boot <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-juli</artifactId> <version>9.0.1</version> </dependency>
  • 27. Spring 5 MVC – Multipart File Size MaxUploadSizeExceededException will be thrown for multipart size overrun • Default Value • Two Properties(Default Value) • spring.servlet.multipart.max-file-size=1MB spring.servlet.multipart.max-request-size=10MB
  • 28. Spring 5 MVC – URL Matcher changed PathPatternParser is alternative to Traditional AntPathMatcher for URL Matching • org.springframework.web.util.patterns.PathPattern Examples: /pages/t?st.html —/pages/test.html, /pages/tast.html /pages/toast.html /resources/*.png — matches all .png files in the resources directory /resources/** — matches all files underneath the /resources/ path, including /resources/image.png and /resources/css/spring.css /resources/{*path} — matches all files underneath the /resources/ path and captures their relative path in a variable named "path"; /resources/image.png will match with ”path" -> "/image.png", and /resources/css/spring.css will match with ”path" -> "/css/spring.css" /resources/{filename:w+}.dat will match /resources/spring.dat and assign the value "spring" to the filename variable
  • 29. Spring 5 MVC – Throwing Exception from Controller ResponseStatusException is Introduced to throw Exception in MVC • SPR-14895:Allow HTTP status exceptions to be easily thrown from Controllers • ResponseEntity(HttpStatus.BAD_REQUEST)? @GetMapping ( "/throw" ) public void getException () { throw new ResponseStatusException( HttpStatus. BAD_REQUEST , "request invalid." ); }
  • 30. Spring 5 WebFlux – WebClient Reactive Web Client introduced in Spring 5, alternative to RestTemplate ● AsyncRestTemplate is deprecated WebClient client= WebClient.create(); Mono<Person> person=client .get() .uri("http://jay-person.cfapps.io/{name}",name) .retrieve() .bodyToMono(Person.class);
  • 31. Spring 5 WebFlux –WebTestClient @RunWith(SpringRunner.class) @SpringBootTest @AutoConfigureWebTestClient public class MicrometerApplicationTests { @Autowired WebTestClient client; @Test public void testWebClient() { client.get().uri("/person/Jay") .exchange() .expectBody(Person.class) .consumeWith(result -> assertThat(result.getResponseBody().getName()).isEqualTo("Jay Lee")); }
  • 32. Spring 5 WebFlux – Server RouterFunction is introduced for functional programming RouterFunction<?> route = route(GET("/users"), request -> ok().body(repository.findAll(), Person.class)) .andRoute(GET("/users/{id}"), request -> ok().body(repository.findOne(request.pathVariable("id")), Person.class)) .andRoute(POST("/users"), request -> ok().build(repository.save(request.bodyToMono(Person.class)).then()) );
  • 33. Spring Boot and Cloud Spring Boot 2.0 will be GA in Feb 2018 ● Spring Cloud Finchley Release Train based on Spring Boot 2.0 ● Spring Cloud Gateway ● Spring Cloud Function
  • 35. Spring 5 – JUnit 5 Jupiter Support Complete Support provided for Jupiter APIs • @SpringJUnitConfig • @SpringJUnitWebConfig • @EnabledIf • @DisabledIf • Parallel Test Execution Support
  • 36. Spring 5 – JUnit 5 Jupiter Support @SpringJUnitConfig(TestConfiguration.class) public class MicrometerApplicationTests { @EnabledIf(expression = "${tests.enabled}", loadContext = true) @Test void givenEnabledIfExpression_WhenTrue_ThenTestExecuted() { assertTrue(true); } @EnabledIf("#{systemProperties['java.version'].startsWith('1.8')}") @Test void givenEnabledIfSpel_WhenTrue_ThenTestExecuted() { assertTrue(true); } }
  • 37. Spring 5 – Deprecated APIs HTTP/2 and Servlet 4.0 • Hibernate 3, 4 • Portlet • Velocity • JasperReports • XMLBeans • JDO • Guava
  • 38. Transforming How The World Builds Software © Copyright 2017 Pivotal Software, Inc. All rights Reserved.