spring Flashcards
What is Spring Framework?
Spring is an umbrella term
for a family of powerful open-source frameworks
which can be used to rapidly create loosely Java applications for reducing the complexity of developing
Spring Frameworks - Overview
The Spring family of frameworks consist of close to 20 modules,
each focusing on a particular task or service
These are grouped into the following layers: 1- Core Container 2- Data Access/Integration 3- Messaging 4- Web 5- AOP (aspect orientation programing) 6- Aspects 7- Instrumentation 8- Test
Core Container IOC
The Spring IOC container is the core of Spring Framework.
The Spring-Core module is responsible for injecting dependencies through either Constructor or Setter methods.
The design principle of Inversion of Control (IOC) emphasizes keeping the Java classes independent of each other and the container frees them from object creation and maintenance.
The container, use for
1- creating objects using Dependency Injection which called Spring Beans.
2- Wiring them together along with configuring
3- Managing their overall life cycles.
The container uses configuration metadata which represent by
Java code / annotations / XML
Context
This modules builds off from the core and bean modules used for more enterprise functionality.
The main feature, Application Context represents the Spring IoC container and is used to instantiate, configure and assemble beans.
SpEL (Spring Expression Language)
A module which provides a powerful expression language which can be used to query and manipulate an object graph at runtime, including setting and getting property values, property assignment, method invocation, accessing array content, collections and indexer
Data Access/Integration
The Data Access/Integration layer provides support for database management or layers of abstraction for ease of use.
JDBC (Java Database Connectivity): A module which provides a layer of abstraction for JDBC ORM (Object Relational Mapping): A module which provides integration layers for ORM APIs, such as JPA, JDO and Hibernate OXM (Object/XML Mapping): A module which provides a layer of abstraction for mapping implementations for JAXB, Castor, XMLBeans, JiBX and XStream JMS (Java Messaging System): A module which provides feature to produce and consume messages. Transaction: A module which provides programmatic and declarative support for transaction management in classes that implement special interfaces as well as POJOs
What do you mean by IoC (Inversion of Control) Container
Spring IoC Container is the core of Spring Framework.
It creates the objects, configures and assembles their dependencies, manages their entire life cycle.
The Container uses Dependency Injection(DI) to manage the components that make up the application.
What do you understand by Dependency Injection?
The main idea in Dependency Injection is that you don’t have to create your objects but you just have to describe how the object should be created.
How many ways of achieving dependency injection
2 major ways of achieving dependency injection are
1-Constructor injection:
2- Setter injection:
the difference between constructor and setter injection
- In constructor injection, partial injection is not allowed
whereas it is allowed in setter injection. - The constructor injection doesn’t override the setter property
whereas the same is not true for setter injection. - Constructor injection creates a new instance if any modification is done.
setter can not creation of a new instance injection. - if the bean has many properties, then constructor injection is preferred.
If it has few properties, then setter injection is preferred.
What are Spring Beans
They are the objects forming the backbone of the user’s application and are managed by the Spring IoC container.
Spring beans are instantiated, configured, wired, and managed by IoC container.
Beans are created with the configuration metadata that the users supply to the container (by means of XML or java annotations configurations.)
What are different ways to configure a class as Spring Bean?
1 - XML-Based configuration: This starts and close with a bean tag
2 - Annotation-Based configuration: the beans can be configured into the component class itself by using annotations on the relevant class, method, or field declaration.
3- Java-based configuration: use of the @Configuration annotated classes and @Bean annotated methods
4-groovy-based configuration, when configuration is file with Groovy code
What is autowiring and name the different modes of it?
Autowiring enables you to inject the object dependency implicitly.
It internally uses setter or constructor injection.
Autowiring can’t be used to inject primitive and string values.
It works with reference only.
There are many autowiring modes
no , byName, byType, constructor, autodetect
Types of IoC Containers in Spring
Spring BeanFactory Container
Spring ApplicationContext Container
What Is Spring MVC (Model-View-Controller)?
Model-View-Controller.
Model component handles the application data
View component handles the presentation layer
Controller handles the incoming requests, creates proper models, and returns the appropriate request to the View