How to do it...

Chapter 8, Reactive Web Application, introduced us to the reactive APIs of FreeMarker and Thymeleaf from Spring Reactive module of Spring 5. Let us now explore the reactive components of Spring Boot by doing the following steps:

  1. There is only one starter POM dependency that is responsible for creating a 100% reactive application that can only be inherited from the Spring Boot 2.0 repository, and that is spring-boot-starter-webflux. Aside from its Spring Reactor APIs, it contains all the necessary beans needed to instantiate a reactive AnnotationConfigServletWebServerApplicationContext that can only be supported by Spring 5:
<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-webflux</artifactId> 
       <exclusions> 
           <exclusion> 
              <groupId>org.springframework.boot</groupId> 
              <artifactId>spring-boot-starter-reactor-netty 
 </artifactId> 
             </exclusion> 
     </exclusions> 
</dependency> 
Since this chapter will be using Tomcat as both the embedded and external server for deployment, exclude Netty plugins from the webflux starter. Moreover, avoid using org.springframework.boot.experimental:spring-boot-starter-web-reactive since it's already deprecated and now successfully replaced by the webflux starter.
  1. Spring Boot 2.0 supports asynchronous components by default because of the webflux starter. Thus, copy SpringAsynchConfig from the previous chapter and drop this in org.packt.spring.boot.config without further configurations. To recall, this class triggered the use of @Async, Callable, and DeferredResult transactions and also generated the needed thread pool from TaskExecutor.
  2. Add the Reactor Core 3.x dependencies to execute Publisher<T>, Mono<T>, and Flux<T> stream operations.
  1. In order to execute Observable<T>, Flowable<T>, and Single<T> operations of RxJava 2.x, add the following Maven dependency:
<dependency> 
   <groupId>io.reactivex.rxjava2</groupId> 
   <artifactId>rxjava</artifactId> 
   <version>2.1.0</version> 
</dependency> 
  1. Copy all service interfaces of ch08 to org.packt.spring.boot.service.
  2. Copy the implementation classes of all the services of ch08 to org.packt.spring.boot.service.impl.
Comment first the lines that execute SecurityContextHolder.
  1. Copy all the controllers except LoginController in ch08 to the package org.packt.spring.boot.controller.
Comment first the lines that execute SecurityContextHolder.
  1. Copy all the form models from the previous chapter to a new package org.packt.spring.boot.model.form.
  2. Also copy the custom property editors AgeEditor and DateEditor to org.packt.spring.boot.editor.
  3. Use the existing DAO implementations as modified by the previous recipe.
  4. Update your views, errors, and message bundle in src/main/resources/config to contain all the properties derived from ch08.
  5. Apply logging to controllers, services, and DAO components.
  6. Lastly, copy all the view pages from the previous ch08 Maven project as follows:
  1. Save all files. Then clean and install to generate WAR files. Manually copy the WAR file from /ch09/target to /webapps of Tomcat 9. Access https://localhost:8443/ch09/menu.html and perform some form handling transactions.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.38.92