Week 7 Spring Framework Overview Flashcards
What are the goals of the Spring Framework?
Lightweight Development with POJOs (Plain Java Objects)
Dependency Injection
- Promotes loose coupling - Loose coupling: Basically, when you're developing, you might use a bunch of different dependencies within a certain class, and you might want to be able to switch out different implementations, so we can utilize DI to achieve this to inject objects that we want to have our IoC container manage o "Switching out dependencies" o Not having to hardcode the instantiation of objects
Minimization of boiler code
What does IoC stand for?
Inversion of Control
What does IoC do?
Inverts control of object creation and application flow to a framework
What is Dependency Injection?
Dependency Injection (DI) is a pattern to implement IoC
"behavior is injected into your classes" Achieves "Loose Coupling"
Describe Dependency Injection
Implementation of inversion of control
- Dependency: some object another object needs in order to function properly
- Injection: passing dependency to a dependent object
- When a Spring bean is instantiated, any dependencies that it requires will be provided (given that those dependencies are also configured as Spring beans)
- Decouples configuration from implementation
Describe Spring Bean
Any object whose lifecycle is managed by Spring (the IoC container)
We specify through configuration what should be a Spring Bean
What is a Core container?
Core container: The core of Spring for creating beans, and also for managing bean dependencies
Beans: spring-beans module Core: spring-core module Context: spring-context module SpEL: Spring Expression Language module
What is a BeanFactory?
BeanFactory is an implementation of the factory design pattern, which removes the need to create programmatic singletons and enables the decoupling of configuration and specification of dependencies from the program logic itself.
What do the Core and Bean modules provide?
The Core and Beans modules provide the fundamental parts of the Spring framework, such as IoC (inversion of control) and DI (dependency injection).
What does the Context build on top of?
The Context builds on top of the Core and Beans modules and allows access to objects in a framework-style manner. Context is what provides us with ApplicationContext, which extends BeanFactory.
List some modules.
Additional modules:
Web module AOP module ORM module Test module JDBC module etc
What are Spring Projects?
Spring projects are built on top of different modules that make up Spring framework. These are “boiler-plate” projects that help us to easily build Spring applications.
Spring Boot Spring Data Spring Security Etc
What is the similarity between a BeanFactory and ApplicationContext?
Both represent an IoC container, which manages the lifecycle of Spring beans
What are some features of BeanFactory?
Older
It lazily instantiates Spring Beans
Must provide a resource object configured for our beans.xml
Example implementation: XmlBeanFactory
XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource(“beans.xml”));
What are some features of ApplicationContext?
Newer
It eagerly instantiates Spring Beans Provides support for annotations Naming convention changed from beans.xml to applicationContext.xml Sub-interface of BeanFactory (meaning this interface extends the BeanFactory interface) Easier integration with Spring AOP Event publication Internationalization features Support for application-layer specific contexts such as WebApplicationContext
Example implementations:
ClassPathXmlApplicationContext FileSystemXmlApplicationContext XmlWebApplicationContext Etc.