spring Flashcards
Lifecycle of a bean
——– : The bean is created or instantiated using a constructor or a factory method.
—————- : The bean’s dependencies are injected, either through constructor injection or setter injection.
—————-: The bean is initialized using its init method or by implementing the InitializingBean interface.
———-: The bean is now ready to be used, and it performs its designated function.
—————–: The bean is destroyed when it is no longer needed, either through a call to its destroy method or by implementing the DisposableBean interface.
Instantiation
Dependency Injection
Initialization
In Use
Destruction
—————- is a fully AOP framework that SpringAOP uses under the hood. However, it requires extensive XML configuration to function, which SpringAOP abstracts away from us.
AspectJ
The —————- method takes an “Authentication” object as its parameter and returns an “—————–” object on successful authentication of the user or else we can have an exception thrown indicating that the user is not authenticated.
authenticate
Authentication
Eagerly instantiates beans (When the application starts, all the beans are ready)
Provides support for annotations
ApplicationContext:
Older
Lazily instantiates beans.
BeanFactory:
———— is an object that creates (instantiates) and holds your Spring Beans, then injects them wherever they’re being called in the application”
A Spring Container
how many instances of a Bean are/can be created and where they are used
“Bean Scope
(Bean scopes)
———-There will only ever be one instance of the Bean with the Bean’s class at one time.
Singleton (default):
(Bean scopes) : A new Bean (with potentially new values) is instantiated every time a Bean is called for.
Prototype
how we connect our beans as dependencies of one another”
Why do we connect beans as dependencies in the first place? Sometimes you need access to other Classes to run their methods etc. (like the Author Class in a Book Class, or a DAO Class in a Service Class.) We can use dependency injection to accomplish this!
Bean Wiring
sets dependencies using a Class’s constructor so that the injection happens at the same time as Class instantiation.
Constructor Injection
uses the setter method of a Class to add the dependencies slightly after instantiation (so after the constructor is invoked)
Setter Injection
————— is the data being sent back (often, we’re sending objects from our models back and forth
————- is what the user sees. They send requests to the server, and things change on their webpage. So they sends requests which updates their view
————— is just our controller classes that take in requests and facilitate sending responses back.
The Model
The View
The Controller
lets us handle HTTP Requests, and provides tools for using the Model-View-Controller design pattern.
Spring MVC
Classes that have other Classes as dependencies
Dependency Injection
are used to configure and customize the behavior of Spring’s dependency injection
Annotations
uses the Java Persistence API (JPA) standard, which provides a set of annotations and APIs for managing relational data. provides a simplified and standardized way of working with data access, allowing developers to write less boilerplate code.
Spring JPA
a standalone Object-Relational Mapping (ORM) framework that provides a way of mapping Java objects to relational databases. mature and widely used technology, providing advanced features such as caching, lazy loading, and optimistic locking.
Hibernate,
————– provides a higher level of abstraction and simplifies database access,
——— provides more control and fine-grained configuration options.
Spring JPA
Hibernate
Can you use Spring JPA by itself?
yes
three ways to define spring beans :
—– Configuration via the <bean> tag in our applicationContext.xml
------ Java Class (@Configuration, @Bean, @Scope) (Won’t show)
------- Driven (stereotype annotations)</bean>
XML
Configuration
Annotation
aotomagically determine the dependencies for you, and then provide them. it abstracts away the dependency injection that it does for you. So to us, it looks automatic and magical.
Autowiring
pieces of the Spring Framework
Spring Modules
Required Modules of spring framework
core
bean
context