




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This document overviews the Spring Framework and Spring Boot, emphasizing their importance in Java development. It covers key concepts like dependency injection, IoC, autowiring, and auto-configuration, explaining how these frameworks simplify web application, REST API, and microservice development. It explores Spring fundamentals, including loose coupling, Spring beans, and annotations, offering insights into building robust, maintainable applications. Designed for beginners, it provides a practical approach with examples and quizzes to reinforce learning. It emphasizes Spring's benefits for managing object lifecycles and dependencies, letting developers focus on business logic. It also addresses best practices for effective Spring development.
Typology: Slides
1 / 231
This page cannot be seen from the preview
Don't miss anything!





























































































Getting Started
Learning Spring & Spring Boot
can be tricky : Lots of new terminology, tools and frameworks
As time passes, we forget things
How do you improve your
chances of remembering
things? Active learning - think & make notes Review the presentation once in a while
How do you put your best foot forward?
Our Approach
You can build a variety of applications using
Java, Spring and Spring Boot: Web REST API Full Stack Microservices
Irrespective of the app you are building: Spring framework provides all the core features Understanding Spring helps you learn Spring Boot easily Helps in debugging problems quickly
In this module, we focus extensively on Spring
Framework
Getting Started with Spring Framework - Why?
Design Game Runner to run games (Mario, SuperContra, Pacman etc) in an iterative approach : Iteration 1 : Tightly Coupled Java Code GameRunner class Game classes: Mario, SuperContra, Pacman etc Iteration 2 : Loose Coupling - Interfaces GameRunner class GamingConsole interface Game classes: Mario, SuperContra, Pacman etc Iteration 3 : Loose Coupling - Spring Level 1 Spring Beans Spring framework will manage objects and wiring Iteration 4 : Loose Coupling - Spring Level 2 Spring Annotations Spring framework will create, manage & auto-wire objects ...
Getting Started with Spring Framework - Approach
Very Few Spring Framework users understand fundamentals: Spring Container vs Spring Context vs IOC Container vs Application Context Java Bean vs Spring Bean Auto Wiring vs Dependency Injection How can you build loosely coupled applications? Making good use of Java Interfaces along with Spring
We spent multiple weeks designing this section to help you understand these fundamentals
This is the most important section of the course: Focus really well to understand the fundamentals Good luck!
Do you want to do well at interviews?
Coupling : How much work is involved in changing something? Coupling is important everywhere: An engine is tightly coupled to a Car A wheel is loosely coupled to a Car You can take a laptop anywhere you go A computer, on the other hand, is a little bit more difficult to move Coupling is even more important in building great so ware Only thing constant in technology is change Business requirements change Frameworks change Code changes We want Loose Coupling as much as possible We want to make functional changes with as less code changes as possible
Let's explore how Java Interfaces and Spring Framework help with Loose Coupling!
Why is Coupling Important?
Question 1 : Spring Container vs Spring Context vs IOC Container vs Application Context
Question 2 : Java Bean vs Spring Bean
Question 3 : How can I list all beans managed by Spring Framework?
Question 4 : What if multiple matching beans are available?
Question 5 : Spring is managing objects and performing auto-wiring. BUT aren't we writing the code to create objects? How do we get Spring to create objects for us?
Question 6 : Is Spring really making things easy?
Spring Questions You Might Be Thinking About
Java Bean : Classes adhering to 3 constraints: 1: Have public default (no argument) constructors 2: Allow access to their properties using getter and setter methods 3: Implement java.io.Serializable
POJO : Plain Old Java Object No constraints Any Java Object is a POJO!
Spring Bean : Any Java object that is managed by Spring Spring uses IOC Container (Bean Factory or Application Context) to manage these objects
Exploring Java Bean vs POJO vs Spring Bean
Constructor-based : Dependencies are set
by creating the Bean using its Constructor
Setter-based : Dependencies are set by
calling setter methods on your beans
Field : No setter or constructor.
Dependency is injected using reflection.
Question: Which one should you use? Spring team recommends Constructor-based injection as dependencies are automatically set when an object is created!
Exploring Spring - Dependency Injection Types
@Primary - A bean should be given preference when multiple candidates are qualified @Qualifier - A specific bean should be auto-wired (name of the bean can be used as qualifier) ALWAYS think from the perspective of the class using the SortingAlgorithm: 1: Just @Autowired : Give me (preferred) SortingAlgorithm 2: @Autowired + @Qualifier : I only want to use specific SortingAlgorithm - RadixSort (REMEMBER) @Qualifier has higher priority then @Primary
@Componentclass QuickSort @Primary implement SortingAlgorithm {} @Componentclass BubbleSort implement SortingAlgorithm {} @Componentclass RadixSort @Qualifier("RadixSortQualifier") implement SortingAlgorithm {} @Componentclass ComplexAlgorithm @Autowiredprivate SortingAlgorithm algorithm; @Componentclass AnotherComplexAlgorithm @Autowiredprivate SortingAlgorithm @Qualifier("RadixSortQualifier") iWantToUseRadixSortOnly;
@Component (..): An instance of class will be managed by Spring framework
Dependency : GameRunner needs GamingConsole impl! GamingConsole Impl (Ex: MarioGame) is a dependency of GameRunner
Component Scan : How does Spring Framework find component classes? It scans packages! (@ComponentScan("com.in28minutes"))
Dependency Injection : Identify beans, their dependencies and wire them together (provides IOC - Inversion of Control) Spring Beans : An object managed by Spring Framework IoC container : Manages the lifecycle of beans and dependencies Types : ApplicationContext (complex), BeanFactory (simpler features - rarely used) Autowiring : Process of wiring in dependencies for a Spring Bean
Spring Framework - Important Terminology