Spring Core Flashcards

1
Q

What are Spring Projects and Spring Modules?

A

Spring Projects are built on Spring modules and provide solutions to other issues faced by enterprise applications.

The Spring Framework consists of features organized into about 20 modules such as CORE Container, Data Access, Web. These modules contain containers and frameworks.

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

What is IOC and what does the IOC Container do?

A

IoC is a design principle which recommends the inversion of different kinds of controls in object-oriented design to achieve loose coupling between application classes. Hollywood Principle: don’t call us we’ll call you

IoC Container (a.k.a. DI Container) is a framework for implementing automatic dependency injection

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

What is dependency injection and what are some of the benefits of using dependency injection?

A

Dependency Injection is a fundamental aspect of the Spring framework, through which the Spring container “injects” objects into other objects or “dependencies”. Simply put, this allows for loose coupling of components and moves the responsibility of managing components onto the container.

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

What types of dependency injection does Spring support?

A

Constructor-Based Injection

Setter Injection

Property-Based Injection

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

What are some differences between BeanFactory and ApplicationContext? Which one eagerly instantiates your beans?

A

BeanFactory loads beans on-demand, while ApplicationContext loads all beans at startup.
ApplicationContext is an interface that extends the BeanFactory interface and allows us to wire our beans and define their relationships to enforce dependency injection
ApplicationContext eagerly instantiates the beans.

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

What is the Spring Bean lifecycle?

A

the spring container gets started. After that, the container creates the instance of a bean as per the request and then dependencies are injected. And finally, the bean is destroyed when the spring container is closed.

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

What is bean wiring? What about autowiring?

A

Bean wiring is the process of combining beans with Spring container. You tell the container what beans are needed and how the container should use dependency injection to tie them together. All beans have to be initialized in an xml file.

Autowiring let Spring figure out dependencies automagically. No need to define beans in .xml

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

What are the different ways that Spring can wire beans?

A

The spring bean autowiring functionality has four modes. These are ‘no’, ‘byName’, ‘byType’ and ‘constructor’.

Through autowiring and through bean wiring in the xml

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

What are the scopes of Spring beans? Which is default?

A

singleton: default
prototype:
request:
session:
global session:

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

What is the concept of component scanning and how would you set it up?

A

This part of “telling Spring where to search” is called a Component Scan. You define the packages that have to be scanned. Once you define a Component Scan for a package, Spring would search the package and all its sub packages for components/beans.

Syntax <context:component-scan></context:component-scan>

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

What are the benefits and limitations of Java configuration?

A

advantages:

  • compile time check
  • refactoring
  • tests flexibility

disadvantages

  • not so good with smaller projects
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does the @Configuration and @Bean annotations do?

A

@Configuration annotation indicates that a class declares one or more @Bean methods

@Bean is a method-level annotation and a direct analog of the XML <bean></bean> element

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

What is @Value used for?

A

@Value is a Java annotation that is used at the field or method/constructor parameter level and it indicates a default value for the affected argument.

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

What is Spring Expression Language? What can you reference using SpEL? What is the difference between $ and # in @value expressions?

A

The Spring Expression Language (SpEL for short) is a powerful expression language that supports querying and manipulating an object graph at runtime.

${} can only do get and #{} can do get and set.

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