Spring Boot Dependency Management - BOM and Uber Jar

Bill of Materials

Spring boot calls its collection of dependencies as BOM or bill of materials.

The Spring Boot starter parent is responsible for most of the default configurations, plugins etc. which aides in the BOM. When adding dependencies, Spring boot tries to add matching dependency versions which will work together well.  Your starter dependencies such as spring-boot-starter-web will not have to specify any versions.

[Example] A Simple Spring Boot REST Web Application

A Spring Boot application uses the @SpringBootApplication annotation over the main executable class. The method call accepts two parameters — the configuration class annotated with @SpringBootApplication annotation and any application arguments. 


Bean Components

We will use a simple bean class based on our previous examples. 

Introduction to Spring Boot

Spring Boot can help us create Spring applications much faster than otherwise. Spring Boot is based on "conventions over configuration" and you have to do very little in configuring an application. For example, you can create a web application with an embedded server in few minutes and you can "just run" them like a desktop application. 

Spring boot home page @ describe itself as follows:

Upcoming Spring Notes

Here I will list out upcoming notes or notes sections (books) on Spring.

  • Aspect Oriented Programming

  • Testing with Spring

  • Transactions with Spring

  • Spring and Data

  • Spring Boot Essentials (In progress)

  • Spring MVC Essentials (In progress)



Initialization and Destruction Code for a Spring Bean

There are different ways to executing some code during initialization and destruction of a bean. We could do that using InitializingBean interface, but there are better approaches using annotations.

We will see two of such approaches here:

  1. Using initMethod and destroyMethod attributes of the @Bean annotation

    • Advantage: We do not need source code access to component classes.

    • Limitation: We cannot specify methods that accept any parameters

[Theory+Example] Bean Scopes in Spring

Beans in Spring can be either singletons or prototypes. Singleton means that only one instance of the bean will be maintained by the Spring and will be returned every time you call the getBean() method. If you set the scope to prototype, then a new bean will be created every time you call the getBean() method.

The default is singleton. In Java configuration, you can specify that a bean scope is prototype by specifying @Scope("prototype") over the bean definition.


Additional Exercises for Mastering Spring Framework 5 Essentials

These are additional exercises you can try out once after learning and practicing all the previous exercises in this section. There will be also hints to make things easier.

  1. Provide examples for autowire for type and autowire by constructor.

  2. Rewrite the following programming using annotations and java configuration:

Configuring Spring 5 Applications

Traditionally Spring applications were configured using only xml configurations. Later annotations such as @Component came and complemented the xml configuration. However later XML configurations were completely replaced by Java configurations that use annotations such as @Bean.

Xml configuration

In xml configuration, you use xml to configure beans.

We can load an xml configuration file from a standalone application as:

Important JAX-RS Annotations

Below JAX-RS annotations aid in mapping a resource class (a POJO) as a web resource:

  • @Path

    • specifies the relative path for a resource class or method.

  • @GET, @PUT, @POST, @DELETE and @HEAD

    • specify the HTTP request type of a resource.

  • @Produces

    • specifies the response Internet media types (used for content negotiation).

  • @Consumes

    • specifies the accepted request Internet media types.


Resource Oriented Architecture

REST follows resource oriented architecture as opposed to the popular service oriented architecture followed by SOAP web services.

Resource-Oriented Architecture has four important concepts:

  • Resources,

  • their names (URIs),

  • their representations and

  • the links between them.



Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within!!!