
This video provides an overview of the entire course.
Problem: The previous Spring Boot versions do not support Java 12 and Servlet 4.0 container. Solution: This video will show viewers that Java 12 can now be used to create Spring Boot 2.2 project, compile, and run its components with some additional mandatory requirements.
Problem: In a tight schedule, it is always not applicable to setup the development environment from scratch. Solution: The easiest way of setting up Spring Boot 2.2 application is through the Spring Initializr service.
Problem: The first portion to implement is the HTTP request layer in a Spring Boot 2.2 way. Solution: This portion will show viewer how easy it is to establish the layer, that will manage HTTP request and response, without implementing MvcConfigurer.
Problem: Request parameters and form data must be captured in an HTTP request transaction. Solution: Just like any other web platform, Spring Boot 2.2 has a way of managing and retrieving request parameters and form data, through its Spring Framework 5.
Problem: There are three different types of form handling transactions supported by HTTP. Solution: Spring Boot 2.2 can implement these three form handling transactions.
Problem: Create views made up of different Java template engines. Solution: Spring has an auto-configured support for Freemarker, Thymeleaf, Groovy templates, and Mustache; but it can be overridden if we use them all at once, in one application.
• Create four category views according to Freemarker, Thymeleaf, Groovy templates, and Mustache view engines
• Create a @Configuration class, to override the respective autoconfiguration of each Java view template engines
• Apply look and feel UI features, using Bootstrap framework
Problem: Create custom exceptions and global error page, that will replace the White Label error page. Solution: Spring Boot 2.2 can implement exception handlers using concepts of Spring 5 framework.
Problem: With the highlight of @ControllerAdvice, AOP can also be used to manage cross-cut implementations. Solution: Spring Boot supports Spring 5 AOP features.
• Create an @Aspect class, that will implement some advice methods
• Highlight @Before, @After, and @Around advice methods, and create @Pointcut expressions
• Use AOP to validate method parameters at runtime, and perform event handling mechanism, using ApplicationEvent
Problem: Other client wants Apache CXF to implement the RESTful services. Solution: Spring Boot 2.2 has a CXF starter module that supports the latest CXF platform.
Signup an account in the Google Cloud Platform portal
• Setup and configure the PostgreSQL datasource through the Cloud SQL service
• Authenticate Docker instance to Google Cloud container, and deploy the dockerized application to Google Cloud container
Problem: Nowadays, Java web-based applications are shifting to JAX-RS 2.1, while creating REST services, due to Servlet 4.0 containers. Solution: Spring Boot 2.2 supports JAX-RS 2.1 with some minor conditions.
Problem: Nowadays, OpenAPI 3.0 is used to provide description, documentation, and code stubbing to RESTful services. Solution: Swagger2 Project is supported by Spring Boot 2.2, to provide metadata to REST endpoints.
Problem: REST endpoints can be executed or run in a service client implementation or testing. Solution: REST endpoints in Spring Boot 2.2 can be executed through Spring 5’s RestTemplate and a third-party plugin named OkHttp.
Problem: Full-stack development and single page applications consume HTTP services to perform repository transactions. Solution: Spring Boot 2.2 can also be used to provide REST services to client-side applications implemented in React or Angular 8.
Problem: How to really test REST web services using Spring Boot’s TestContext container during development. Solution: Spring Boot 2.2 has a Test starter module that automatically imports JUnit 5, Mockito, and AssertJ for unit and integration during development.
Problem: Using Spring JDBC module in retrieving and persisting data using relational datastore lacks transactional management operations. Solution: Spring Boot 2.2 has a Spring Data JPA which can offer an easy-to-setup, reliable, and robust persistence framework in building DAO layer.
Problem: Some requirement requires MyBatis framework instead of the boilerplate Hibernate 5 framework. Solution: Here is Spring MongoDB starter module, which automatically configures the MyBatis framework.
• Create @Mapper classes
• Implement the query methods using the @Insert, @Delete, @Update, and @Select
• Test repository classes using @MybatisTest
Problem: Relational databases sometimes need administration when data capacity gets humongous. Solution: Spring MongoDB is a starter module that can persist and retrieve data using MongoDB NoSQL datastore.
• Create and utilize MongoRepository<T, ID>
• Implement @Query and transactional operations
• Test repository classes using de.flapdoodle.embed and @DataMongoTest
Problem: Application may apply complex transactions such as JOIN, sorting, pagination, and domain-based operations. Solution: Spring Data JPA 2.2, as well as, Spring Data MongoDB can support all of those requirements with less coding.
• Implement inner, left, right join using @Query
• Generate sorted and paginated results using PagingAndSortingRepository<T, ID>
• Create query and transactional operations using QueryDSL components
Problem: Application is required to expose query and transactional operations through REST endpoints. Solution: Spring Data REST together with Spring Data JPA 2.2 or Spring Data MongoDB can help implement RESTful services.
Problem: The application wants to focus on customized HAL results of REST endpoints generated using non-complex and loosely coupled operations. Solution: Spring Data HATEOS can help application expose JPA data using customized HAL template.
• Generate hypermedia links using WebMvcLinkBuilder’s helper methods
• Wrap results using EntityModel<T> and CollectionModel<T>
• Consume and execute REST endpoints using Traverson API
Problem: Security framework usually is difficult to implement because of its cumbersome setup and coding. Solution: Spring Security 5.2 is an easy-to-setup and reliable framework to use.
Problem: Hardcoding the security details is prohibited in setting-up the security model. Solution: Spring Security 5.2 can implement a database-based authentication, without so many setup requirements.
Problem: Application requires the best password encoding algorithm so far in generating the passphrase. Solution: Aside from BCryptPasswordEncoder, the framework can also support slow hashing algorithm in protecting the password.
• Apply and setup the needed PBKDF2PasswordEncoder
• Use the appropriate SCrypt algorithm using the SCryptPasswordEncoder
• Apply the latest Argon2 encoding algorithm through its password encoder
Problem: Logging into the system does not only require authentication, but some role-based authorization mechanism to further secure the application. Solution: Roles and permission can be established using the GrantedAuthority component of the framework. Not only during login, these roles can also provide restricted access to some portion of the application.
• Build the GrantedAuthority of each user profile through the UserDetailService
• Modify the HttpSecurity configuration to include hasRole() or hasAuthority() rules
• Apply method security to @Controller, services and DAO transactions using @EnableGlobalMethodSecurity (prePostEnabled=True)
Problem: What if the redirect-Login-Page and success-logout-page depends on the user role? What if a RememberMe authentication feature is needed to be applied? How can we control user sessions? Solution: Spring Security 5.2 is extensible enough to allow customization of its core components, handlers, providers, and filters in order to cater create a more desirable security solution.
Problem: The application wants to implement a session-less authentication process. Solution: Spring Security can comply to some security specification like the JWT specification in order to implement authentication process without using any sessions.
• Provide a custom @Controller that will generate JWT token to be used in a session-less and token-based authentication process
• Utilize the JWTs utility class in generating and validating the token, and decoding the password from this token
• Implement a custom OncePerRequestFilter that will validate the JWT token in the Authentication request header bearer value
Problem: Application prefers login mechanism from a third-party authorization provider. Solution: Spring Security can also comply with OAuth2 specification, and can even recognize OpenID Connect protocol from an identity provider like Okta.
• Setup an Okta authorization server and OpenID Connect application, for the OAuth2 client credentials using an Okta account
• Through the Okta Spring Security module, implement an access key exchange, between the Okta authorization server and the client application
• Setup the needed client properties in the application.properties file
Problem: The application wants to use a customized Spring Boot 2.2 application as an authorization server. Solution: Spring Security has a Spring Security OAuth module that can help build an authorization provider from level 0.
Problem: How to breakdown our previous farm harvest management application into microservices, with less time spent in configuration and setup? Solution: Spring Boot 2.2 is a platform that requires less time in building microservices.
Setup the JWT token-based security protocol through Spring Security 5.2
• Use the EndPointRequest API of Spring Security, to apply authorization mechanism to the Actuator endpoints
• Implement the necessary exception handlers
Problem: Can we use third-party tools, to enhance the monitoring capability of the microservice application? Solution: Since the Spring Boot 2.2’s Actuator registry is internally provided by the micrometer.io, we can integrate to it some third-party client monitoring tool such as Prometheus.
• Enable and activate the Prometheus Actuator endpoint
• Download and install Prometheus client monitoring application
• Inject into the application context the MeterRegistryCustomizer, to customize further the Prometheus monitoring mechanism
Problem: Can we apply authentication and authorization to the Actuator endpoints? Solution: Spring Security 5.2 can also be used to secure the Actuator endpoints, and there are APIs it can provide, to build the authorization rules to the endpoints.
Problem: Can we implement and add some custom and project-related Actuator services? Solution: Aside from modifying its default endpoints, custom Actuator services and endpoints can be created and added to the platform.
• Customize the process of some existing Actuator by overriding APIs, such as InfoContributor and HealthIndicator
• Implement and configure custom Actuator services with @Endpoint
• Implement and setup custom Actuator endpoints with @RestEndpointController or @EndpointController
Problem: If we have several microservices, are there standards that we can apply, so as to organize them? Solution: There are several core microservice design patterns that can be used to build an organized enterprise microservices.
• Apply API Gateway design pattern by applying the Spring Cloud Gateway
• Apply Service Discovery design pattern, by using the Spring Cloud Netflix Eureka
• Apply the Circuit Breaker and Distributed Tracing design patterns
Problem: How to build an application that has a fully working reactive components from DAO layer up to the views? Solution: Spring Boot 2.2 has an enhanced and improved reactive Spring Data MongoDB, ViewResolver, and @Controllers that can support transporting Mono<T> and Flux<T> model attributes.
Problem: Are we only limited to one reactive ViewResolver in Spring Boot 2.2 platform to render data in a reactive stream? Solution: Spring Boot 2.2 supports more than one reactive ViewResolvers.
Problem: Is Functional Web Framework still supported by Spring Boot 2.2? Solution: Spring Boot 2.2 has a more enhanced RouterFunction<T> and HandlerFunction<T>.
Problem: How can we apply a reactive JDBC transaction, if Spring Boot 2.2 cannot support a reactive Spring Data JPA? Solution: Spring Boot 2.2 has a newly released reactive JDBC module called the Spring Data R2DBC.
Problem: Can we implement and add some custom and project-related Actuator services? Solution: Aside from modifying its default endpoints, custom Actuator services and endpoints can also be created and added to the platform.
• Customize the process of some existing Actuator by overriding APIs, such as InfoContributor and HealthIndicator
• Implement and configure custom Actuator services with @Endpoint
• Implement and setup custom Actuator endpoints with @RestEndpointController or @EndpointController
Problem: A microservice application requires reactive REST endpoints and server-sent events. Solution: Spring WebFlux starter module has @RestController and functional web framework that can expose reactive stream data.
• Use @RestController of Spring WebFlux that can expose Flux<T> and Mono<T> resources
• Implement RouterFunction<T> and HandlerFunction<T> that will expose GET, POST, and other HTTP response
• Apply reactive @RestController in exposing the ServerSentEvent resource type
Problem: Can we build a working and fully reactive Spring Boot 2.2 application in Kotlin? Solution: Spring Boot 2.2 supports building a reactive web application using Kotlin.
Problem: How to containerize Spring Boot 2.2 application with Docker? Solution: Docker has CLI commands that can be used to deploy application to the Docker cloud container.
Problem: Is there a plugin that will automate the dockerization instead of manually running the Docker CLI commands? Solution: There are Docker Gradle dependencies that can be integrated into the project’s Gradle build which can be configured to automate the deployment.
• Setup the Palantir Docker Gradle plugin
• Implement the Gradle task for creating the Docker image
• Implement the Gradle task for running the Docker image
Problem: How can we deploy Spring Boot 2.2 application to Pivotal Web Service (PWS) container? Solution: PWS can now run deployed Spring Boot 2.2 applications.
Problem: Can we deploy the application to Microsoft Azure? Solution: Microsoft Azure supports the deployment of Spring Boot 2.2 applications.
Problem: Can we deploy the application to a Google Cloud container? Solution: Google Cloud Platform always supports deployment of Spring Boot 2.2 applications.
Building web application has been a challenge for many Java developers because of the complexities of their software requirements, leading to a bloated and unmanaged framework library repository and configurations. Spring Boot 2.x, a feature-rich platform built from the Spring 5.x framework, is created by to help developers solve their complex problems with fewer configurations but with strong dependency management features.
In this course, you will learn how to create various modules in a Human Resources Information System (HRIS) such as employee timesheets, leave management, and profiling. You will use Spring Boot 2.x to create your HRIS app while integrating Spring Web MVC, Spring WebFlux, Spring Data, RESTful web services, and clients. Above all, you'll use the latest version of Spring Security—5.0—to secure your apps and OAuth 2.x to implement an OpenID connection. You'll apply reactive programming with its Spring Web Flux and Project Reactor features. Finally, you will deploy your apps and services using some popular cloud and container platforms such as Spring Cloud Foundry, Docker, and AWS.
By the end of the course, you will be confident in implementing the core features of Spring Boot 2.x to create scalable, optimal, and robust enterprise web applications.
About the Author
Sherwin John Calleja Tragura started his career as a Java developer by focusing on the Documentum and Alfresco document management systems. His first exposure to mobile applications started in 2010 when he first installed and used the Alfresco mobile application, which featured core document content services.
He is currently a technical corporate trainer and a subject matter expert on Java, JEE, and Spring application development. He is a certified EMC Documentum and OCP Java 7 Associate. He authored the following Packt books—Spring MVC Blueprints and Spring 5 Cookbook and also a Packt video course: Jakarta EE 8 Recipes. Before that, he was a technical editor for Alfresco Share, Alfresco 3 Records Management, Mastering Hibernate, and Delphi Cookbook.