SlideShare a Scribd company logo
© 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 (20)

PDF
rx-java-presentation
Mateusz Bukowicz
 
PDF
Dropwizard
Tetiana Saputo
 
PDF
Introduction to Retrofit and RxJava
Fabio Collini
 
PPTX
Supercharged java 8 : with cyclops-react
John McClean
 
PDF
Gradle - Build System
Jeevesh Pandey
 
PDF
FlutterでGraphQLを扱う
IgaHironobu
 
PDF
Reactive Applications with Apache Pulsar and Spring Boot
VMware Tanzu
 
PDF
Clean Architecture on Android
Tianming Xu
 
PDF
Database migration with flyway
Jonathan Holloway
 
PPTX
Dropwizard Internals
carlo-rtr
 
PDF
Building Scalable Stateless Applications with RxJava
Rick Warren
 
ODP
Reactors.io
Knoldus Inc.
 
PDF
Take Control of your Integration Testing with TestContainers
Naresha K
 
PPT
Whats New in MSBuild 3.5 and Team Build 2008
wbarthol
 
PPTX
What’s expected in Spring 5
Gal Marder
 
PDF
Towards Safe Refactoring for Intelligent Parallelization of Java 8 Streams
Raffi Khatchadourian
 
PPTX
Javantura v3 - Going Reactive with RxJava – Hrvoje Crnjak
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
PDF
Bulding a reactive game engine with Spring 5 & Couchbase
Alex Derkach
 
ODP
Introduction to Scala Macros
Knoldus Inc.
 
PDF
12 Factor App: Best Practices for JVM Deployment
Joe Kutner
 
rx-java-presentation
Mateusz Bukowicz
 
Dropwizard
Tetiana Saputo
 
Introduction to Retrofit and RxJava
Fabio Collini
 
Supercharged java 8 : with cyclops-react
John McClean
 
Gradle - Build System
Jeevesh Pandey
 
FlutterでGraphQLを扱う
IgaHironobu
 
Reactive Applications with Apache Pulsar and Spring Boot
VMware Tanzu
 
Clean Architecture on Android
Tianming Xu
 
Database migration with flyway
Jonathan Holloway
 
Dropwizard Internals
carlo-rtr
 
Building Scalable Stateless Applications with RxJava
Rick Warren
 
Reactors.io
Knoldus Inc.
 
Take Control of your Integration Testing with TestContainers
Naresha K
 
Whats New in MSBuild 3.5 and Team Build 2008
wbarthol
 
What’s expected in Spring 5
Gal Marder
 
Towards Safe Refactoring for Intelligent Parallelization of Java 8 Streams
Raffi Khatchadourian
 
Javantura v3 - Going Reactive with RxJava – Hrvoje Crnjak
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Bulding a reactive game engine with Spring 5 & Couchbase
Alex Derkach
 
Introduction to Scala Macros
Knoldus Inc.
 
12 Factor App: Best Practices for JVM Deployment
Joe Kutner
 

Similar to Spring5 New Features (20)

PDF
Spring5 New Features - Nov, 2017
VMware Tanzu Korea
 
PDF
PUC SE Day 2019 - SpringBoot
Josué Neis
 
ODP
springmvc-150923124312-lva1-app6892
Tuna Tore
 
ODP
Java Spring MVC Framework with AngularJS by Google and HTML5
Tuna Tore
 
PDF
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
Appster1
 
PDF
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
Appster1
 
KEY
Multi Client Development with Spring
Joshua Long
 
PDF
Rediscovering Spring with Spring Boot(1)
Gunith Devasurendra
 
PDF
Introducing Spring Framework 5.3
VMware Tanzu
 
PDF
using Mithril.js + postgREST to build and consume API's
Antônio Roberto Silva
 
PPTX
SpringBootCompleteBootcamp.pptx
SUFYAN SATTAR
 
PPTX
Spring boot Introduction
Jeevesh Pandey
 
PPTX
Angular beans
Bessem Hmidi
 
PDF
Spring design-juergen-qcon
Yiwei Ma
 
PDF
Java servlet technology
Minal Maniar
 
PPTX
C#on linux
AvarinTalks
 
PPTX
Springboot2 postgresql-jpa-hibernate-crud-example with test
HyukSun Kwon
 
PPTX
Angular 2 Migration - JHipster Meetup 6
William Marques
 
KEY
Integrating Wicket with Java EE 6
Michael Plöd
 
PDF
Spring Boot
HongSeong Jeon
 
Spring5 New Features - Nov, 2017
VMware Tanzu Korea
 
PUC SE Day 2019 - SpringBoot
Josué Neis
 
springmvc-150923124312-lva1-app6892
Tuna Tore
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Tuna Tore
 
dokumen.tips_rediscovering-spring-with-spring-boot1 (1).pdf
Appster1
 
dokumen.tips_rediscovering-spring-with-spring-boot1.pdf
Appster1
 
Multi Client Development with Spring
Joshua Long
 
Rediscovering Spring with Spring Boot(1)
Gunith Devasurendra
 
Introducing Spring Framework 5.3
VMware Tanzu
 
using Mithril.js + postgREST to build and consume API's
Antônio Roberto Silva
 
SpringBootCompleteBootcamp.pptx
SUFYAN SATTAR
 
Spring boot Introduction
Jeevesh Pandey
 
Angular beans
Bessem Hmidi
 
Spring design-juergen-qcon
Yiwei Ma
 
Java servlet technology
Minal Maniar
 
C#on linux
AvarinTalks
 
Springboot2 postgresql-jpa-hibernate-crud-example with test
HyukSun Kwon
 
Angular 2 Migration - JHipster Meetup 6
William Marques
 
Integrating Wicket with Java EE 6
Michael Plöd
 
Spring Boot
HongSeong Jeon
 
Ad

More from Jay Lee (10)

PDF
Spring on Kubernetes
Jay Lee
 
PDF
Knative And Pivotal Function As a Service
Jay Lee
 
PDF
Knative and Riff
Jay Lee
 
PDF
CF Korea Meetup - Spring Cloud Services
Jay Lee
 
PDF
SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire
Jay Lee
 
PPTX
CF Korea Meetup - Gemfire on PCF
Jay Lee
 
PDF
JavaEE6 - 설계 차원의 단순성
Jay Lee
 
PDF
Java8 - Oracle Korea Magazine
Jay Lee
 
PPTX
Java EE7
Jay Lee
 
PDF
Java 8 & Beyond
Jay Lee
 
Spring on Kubernetes
Jay Lee
 
Knative And Pivotal Function As a Service
Jay Lee
 
Knative and Riff
Jay Lee
 
CF Korea Meetup - Spring Cloud Services
Jay Lee
 
SpringCamp 2016 - Apache Geode 와 Spring Data Gemfire
Jay Lee
 
CF Korea Meetup - Gemfire on PCF
Jay Lee
 
JavaEE6 - 설계 차원의 단순성
Jay Lee
 
Java8 - Oracle Korea Magazine
Jay Lee
 
Java EE7
Jay Lee
 
Java 8 & Beyond
Jay Lee
 
Ad

Recently uploaded (20)

PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 

Spring5 New Features

  • 1. © Copyright 2017 Pivotal Software, Inc. All rights Reserved. Version 1.0 Jay Lee([email protected]) 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 = “[email protected]”; Jsonb jsonb = JsonbBuilder.create(); String JsonToString = jsonb.toJson(person); System.out.println(JsonToString ); person = jsonb.fromJson("{"name":”Jay Lee","age":1,”email":”[email protected]"}", 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.