Spring Flashcards

1
Q

What is Spring framwork?

A

An open source development framework for Enterprise Java. With Spring we can develop large-scale complex Java applications very easily. It is based on good design patterns like Dependency Injection and Aspect Oriented Programming.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the benefits of spring?

A

Lightweight: basic spring framework is small in size.
Container: is provides the basic container that creates and ma ages the life cycle of application objects like POJO.
Dependency Injection: it provides loose coupling by dependency injection. Objects specify their dependencies to the Spring container.
Aspect Oriented Programming: This helps with separating application business logic from system services that are common across all business logic.
Transaction Management: spring provides a framework for transaction management that is scalable.
MVC: for web applications spring provides MVC framework based on the MVC design pattern.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the modules in the Core Container in spring?

A

Core Module, Bean Module, Context Module, Spring Expression Language Module.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the modules in the Data Access layer of Spring framework?

A

JDBC: abstraction layer to remove tedious JDBC coding.
ORM module: Integration layers for Object Relational Mapping
OXM module: abstraction layer to support Object XML mapping.
Transactions Module: Transaction management for POJO classes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What kind of testing can be done in the Spring Test Module?

A

Provides support for Unit testing as well as Integration testing of Spring components. It also gives ability to mock objects to test code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the use of BeanFactory?

A

This is the main class that helps in implementing Inversion of Control pattern, based on the factory design pattern.
It separates the configuration and dependencies of an application from the rest of the application code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is XMLBeanFactory in Spring?

A

It is one of the most useful implementations of BeanFactory in Spring. It loads its beans based on the definitions mentioned in an XML file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the benefits of JDBC abstraction layer module in Spring?

A

Helps in keeping the database code clean & simple.
Prevents problems that result from failure to close database resources.
Provides a layer of useful exceptions.
Based on Springs AOP module.
Provides transaction management.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How does Spring support Object Relational Mapping integration?

A

Spring supports this by providing ORM module. This module helps integrating with popular ORM frameworks like Hibernate.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How does the Web module work in Spring framework?

A

Web module is built on application context module that provides context for web-based applications.
This module also supports integration with popular web frameworks like Jakarta Struts, JSF etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the main uses of Spring MVC module?

A

Spring-webmvc module (web-servlet module). Based on Web Model View Controller pattern. Helps with the integration of Spring with other MVC frameworks. Supports IoC to provide clear separation of controller logic from business objects. Provides clean separation between domain model code and web forms.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the purpose of Spring configuration file?

A

Spring applications can be configured by an XML file. This contains information of classes and how they should be configured.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the benefits of ApplicationContext in Spring?

A

Bean factory methods: these are used to access application components.
Load File Resources: helps in loading file resources in a generic fashion.
Publish Events: enables publishing events to registered listeners.
Parent Context: ability to inherit from a parent context.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the main components of a typical Spring based application?

A

Spring configuration XML file: used to configure the application.
API interfaces: Definition of API interfaces for functions provided by application.
Implementation: Application code with implementation of APIs
Aspects: Spring Aspects implemented by the application.
Client: Application at client side that is used for accessing functions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Explain Dependency Injection concept in spring?

A

It is a software design pattern, used to implement Inversion of Control in Spring framework. With this pattern, we do not create objects in an application by calling new. Rather, we describe how an object should be created. In this way, creation of an object is not tightly coupled with another object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the advantages of Dependency Injection?

A

Reduces coupling between a class and its’ dependencies.
Enables us to do concurrent or independent software development.
The client can be configured in multiple ways, it just needs to work with the given interface.
DI applications provide more ease and flexibility in testing, these can be tested in isolation in a Unit Test.

17
Q

What is a Spring Bean?

A

A Spring Bean is a POJO that is created and managed by the Spring container. There can be multiple beans in a spring application, but all are instantiated and assembled by the Spring container. In general, a bean is a Singleton type.

18
Q

What does the definition of a Spring Bean contain?

A

A Spring Bean definition contains configuration metadata for the bean, this metadata is used by Spring to create the bean, manage its lifecycle, resolve its dependencies.

19
Q

What are the design-patterns used in Spring framework?

A

Singleton - by default beans are singleton
Template - used in many classes like JDBCTemplate, RESTTemplate.
DI - this pattern is the core behind the design of BeanFactory and ApplicationContext.
Proxy - AOP heavily uses proxy.
Factory Pattern - used to create an instance of an object.

20
Q

What is Bean wiring?

A

A spring container is responsible for injecting dependencies between beans, this process of connecting beans is called wiring.

21
Q

What is Autowiring?

A

Autowiring is a Spring feature in which the container can automatically wire the beans by reading the config file. @Autowired

22
Q

What is Java-based configuration in spring?

A

Spring allows for Java-based configuration in which deelop can specify config by using java annotations. YOu can use annotations like @Configuration @Bean @Import @Service etc.

23
Q

What is the purpose of JdbcTemplate?

A

It contains many convenient methods for regular tasks like converting data into primitives or objects, executing prepared or callable statements etc. It makes it very easy to work with database in our application and provides good error handling support.

24
Q

What types of Object Relational Mapping (ORM) are supported by Spring?

A

Hibernate, Spring JPA (Java Persistence API), TopLink, Apache Object Relational Bridge

25
Q

How does Spring MVC work?

A

Spring Model View Controller framework is based on Inversion of Control principle. It separates the business objects from controller.

26
Q

What is controller in Spring MVC framework?

A

Controller is an interface which receives HTTPServletRequest and HTTPServletResponse in web applications. Controllers interpret user input and transforms it into a model.

27
Q

What is @RequestMapping in spring?

A

We use @RequestMapping annotation to map a web request to either a class or a handler method. WE can specify the path of the URL as well as HTTP method like - GET PUT POST etc.

28
Q

What is @Controller?

A

For creating controller classes in a Spring MVC project

29
Q

What is @RequestMapping?

A

This annotation maps the URI to a controller handler method in Spring MVC.

30
Q

What is @ResponseBody?

A

For sending an Object as response we use this annotation.

31
Q

What is @PathVariable?

A

To map dynamic values from a URI to handler method arguments, we use this annotation.

32
Q

What is @Autowired

A

This annotation indicates to spring for auto-wiring dependencies in beans.

33
Q

What is @Service?

A

This annotation marks the service classes in spring.

34
Q

What is @Scope?

A

We can define the scope of a Spring bean with this annotation.

35
Q

What is @Configuration?

A

This annotation is for Java Based Spring Configuration.

36
Q

What are some of the best practices in Spring Framework?

A

Configure bean dependencies as much as possible, unless there is a good reason, we try to avoid autowiring.
We should just use what we need in our application and remove any unused dependencies.
For application properties it is good to create a properties file and read it in the Spring configuration file.
Annotations are useful in smaller applications, but in larger applications annotations can become an overhead, so it is easier to maintain configurations in XML files.