Book Image

Hands-On High Performance with Spring 5

By : Chintan Mehta, Subhash Shah, Pritesh Shah, Prashant Goswami, Dinesh Radadiya
Book Image

Hands-On High Performance with Spring 5

By: Chintan Mehta, Subhash Shah, Pritesh Shah, Prashant Goswami, Dinesh Radadiya

Overview of this book

While writing an application, performance is paramount. Performance tuning for real-world applications often involves activities geared toward detecting bottlenecks. The recent release of Spring 5.0 brings major advancements in the rich API provided by the Spring framework, which means developers need to master its tools and techniques to achieve high performance applications. Hands-On High Performance with Spring 5 begins with the Spring framework's core features, exploring the integration of different Spring projects. It proceeds to evaluate various Spring specifications to identify those adversely affecting performance. You will learn about bean wiring configurations, aspect-oriented programming, database interaction, and Hibernate to focus on the metrics that help identify performance bottlenecks. You will also look at application monitoring, performance optimization, JVM internals, and garbage collection optimization. Lastly, the book will show you how to leverage the microservice architecture to build a high performance and resilient application. By the end of the book, you will have gained an insight into various techniques and solutions to build and troubleshoot high performance Spring-based applications.
Table of Contents (14 chapters)

Spring projects

The Spring Framework provides different kinds of projects for different infrastructure needs, and also helps to explore solutions to other problems in the enterprise application: deployment, cloud, big data, and security, among others.

Some of the important Spring projects are listed as follows:

  • Spring Boot
  • Spring Data
  • Spring Batch
  • Spring Cloud
  • Spring Security
  • Spring HATEOAS

Let's discuss them in detail.

Spring Boot

Spring Boot provides support to create standalone, production-grade, Spring-based applications that you can just run.

Spring Boot also provides some of the following features out of the box, by taking an opinionated view of how applications have to be developed:

  • Provides support for developing standalone Spring applications
  • Embeds Tomcat, Jetty, or Undertow directly, with no need to deploy WAR files
  • Allow us to externalize configuration to work in different environments with the same application code
  • Simplifies Maven configuration by providing opinionated starter POMs
  • Eliminates the need for code generation and the requirement for XML configuration
  • Provides support for production features like metrics, health checks, and application monitoring

We will look at Spring Boot in depth in Chapter 12, Spring Boot Microservice Performance Tuning.

Spring Data

The main goal of the Spring Data project is to provide an easy and consistent Spring-based model to access data and other special features, to manipulate SQL-and NoSQL-based data stores. It also tries to provide an easy way to use data access technologies, map-reduce frameworks, relational and non-relational databases, and cloud-based data services.

Some of the important features are as follows:

  • Provides support for integration with custom repository code
  • Provides repository and object-mapping abstractions by deriving dynamic queries using repository method names
  • Advanced integration support with Spring MVC controllers
  • Advanced support for transparent auditing features such as created by, created date, last changed by, and last changed date
  • Experimental integration support for cross-store persistence

Spring Data provides integration support for the following data sources:

  • JPA
  • JDBC
  • LDAP
  • MongoDB
  • Gemfire
  • REST
  • Redis
  • Apache Cassandra
  • Apache Solr

Spring Batch

Spring Batch facilitates essential processing for large volumes of records, including logging/tracing, transaction management, job processing statistics, job restart, skip, and resource management, by providing reusable functions. It also provides more advanced technical services and features that will enable extremely high-volume and high-performance batch jobs using optimization and partitioning techniques.

Important features of Spring Batch are as follows:

  • The ability to process data in chunks
  • The ability to start, stop and restart jobs, including the ability to restart, in the case of failed jobs, from the point where they failed
  • The ability to retry steps or to skip steps on failure
  • Web-based administration interface

Spring Cloud

It is not an overstatement to say the world is moving to the cloud.

Spring Cloud provides tools for developers to build common patterns in distributed systems. Spring Cloud enables developers to quickly build services and applications that implement common patterns to work in any distributed environment.

Some of the common patterns implemented in Spring Cloud are as follows:

  • Distributed configuration
  • Service registration and discovery
  • Circuit breakers
  • Load balancing
  • Intelligent routing
  • Distributed messaging
  • Global locks

Spring Security

Authentication and authorization are the essential parts of enterprise applications, both web applications and web services. Spring Security is a powerful and highly customizable authentication and access control framework. Spring Security focuses on providing declarative authentication and authorization to Java applications.

Important features in Spring Security are as follows:

  • Comprehensive support for both authentication and authorization
  • Good support for integration with servlet APIs and Spring MVC
  • Module support for integration with Security Assertion Markup Language (SAML) and Lightweight Directory Access Protocol (LDAP)
  • Providing support for common security attacks such as Cross-Site Forgery Request (CSRF), session fixation, clickjacking, and so on

We will discuss how to secure web applications with Spring Security in Chapter 4, Spring MVC Optimization.

Spring HATEOAS

The main purpose of Hypermedia As The Engine Of Application State (HATEOAS) is to decouple the server (the service provider) from the client (the service consumer). The server provides the client with information on other possible actions that can be performed on the resource.

Spring HATEOAS provides a HATEOAS implementation, especially for the REpresentational State Transfer (REST) services implemented with Spring MVC.

Spring HATEOAS has the following important features:

  • A simplified definition of links pointing to service methods, making the links less fragile
  • Support for JSON and JAXB (XML-based) integration
  • Support for hypermedia formats such as Hypertext Application Language (HAL)

In the next section, we will understand the mechanism of Spring's IoC container.