Spring Core Flashcards
What are Spring Projects?
Application frameworks that provide solutions to issues faced by enterprise applications. An example is Spring Boot, a popular framework to develop microservices.
Other Spring Projects: Spring Cloud, Spring Data, Spring Integration, Spring Security
What are Spring Modules?
Spring Modules are the building blocks of Spring Projects and Spring Framework. They are what you see when you look under the hood of Spring Projects.
An example of an important container of modules is the Spring Core container, which holds the core, beans, context, and expression language modules.
What is IOC?
IOC- Inversion of Control, is when Spring frameworks take control of creating objects & injecting dependencies into your code. It is implemented by the Core Container.
It is helpful in achieving loose coupling between classes
What is dependency injection? Benefits?
A technique in which an object receives other objects/ “dependencies” that it needs to run.
*The code that passes dependencies to an object is called the ‘injector’.
Benefits:
- allows for loose coupling of components
- puts responsibility of managing them onto container
Types of dependency injection Spring supports
Constructor:
- more secure, dependencies required
- enables implementation of immutable objects
Setter injection:
- allows partial dependencies
- easily change values
What is the Spring Bean life-cycle?
Container started -> bean instatiated -> depenedencies injected -> container is closed -> bean is destroyed.
Management of beans is conducted by the BeanFactory or Application Context
What is the Bean Factory?
- an interface that is a container for instantiating, configuring, and managing beans
- loads on-demand (more lightweight) based on a configuration file or using Java Configuration.
What is Application Context?
- implements the BeanFactory interface
- the central interface within a Spring app, used for providing configuration info to the app
What is bean wiring?
the process of combining & establishing dependencies between beans
What is auto-wiring?
@Autowired
- tells the container to enable dependency injection
- declare all bean dependencies
- container can auto-wire relationships between beans
The default scope of a bean is “singleton” (T/F)
True
What are the Stereotype annotations in Spring?
@Component:
@Service:
@Repository:
@Controller: front controllers and responsible to handle user requests and return the appropriate response
What does the @Configuration do?
indicates that a class has one or more @Bean methods to be processed by the Spring container to generate bean definitions and service requests
What does @component do?
allows Spring to detect our beans by marking the beans as Spring’s managed components.
what does @Repository do?
indicates a class as a repository
- able to store data - retrieving & search data