Spring Flashcards

1
Q

What is the Spring Framework?

A

The Spring Framework is an application framework and inversion of control container for the Java platform. One of the core functions of the Spring Framework is dependency injection, which is accomplished through the use of a inversion of control container, known as the ApplicationContext. The framework integrates with other specifications, namely:

Dependency Injection (JSR 330)
Servlet API (JSR 340)
Bean Validation (JSR 303)
JPA (JSR 338)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the goals of Spring?

A

Lightweight development with Java POJOs
Dependency injection to promote loose coupling
Declarative programming with Aspect-Oriented Programming (AOP)
Minimize boilerplate Java code

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

What is Dependency Injection?

A

The process of the Spring Framework actually injecting an instance of a dependency into a component (through auto-wiring or manual bean wiring)

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

What is Autowiring?

A

The process in which the Spring Framework identifies dependencies within a component, finds the corresponding component implementations and instantiates the dependency (or grabs an existing instance)

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

How manual wiring works?

A

Manual bean wiring is the process in which a bean’s dependencies are associated with the parent bean through explicit configuration. If leveraging constructor injection, this is done in XML configuration by including a constructor-arg tag with a bean id specified in the ref attribute.

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

How automatic wiring works?

A

If we let Spring scan our packages for us, using component scanning, we do not need to provide explicit bean definitions in an XML file, nor within some configuration class. Instead, Spring will scan the specified package for classes annotated with @Component (or another stereotype annotation) and create the bean definitions for them from the class declaration.

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

What are the bean scopes?

A

Singleton, Prototype, Request, Session, Application, WebSocket

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

What is ApplicationContext?

A

It is an interface that describe the Inversion of Control Container. The most important implementations of this interface are:
ClassPathXmlApplicationContext
AnnotationConfigApplicationContext
WebApplicationContext

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

What is a BeanFactory?

A

A bean factory is just that, a implementation of the factory design pattern which is used to create Spring beans. The BeanFactory interface is implemented by objects that hold a number of bean definitions, each uniquely identified by a String name. Depending on the bean definition, the factory will return either an independent instance of a the object, or a single shared instance (a singleton scoped to the factory instance). The point of this approach is that the BeanFactory is a central registry of application components, and centralizes configuration of application components.

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

What is the Bean lifecycle

A
Instantiate
Populate Properties
setBeanName
setBeanFactory
setApplicationContext
PreInitialization
afterPropertiesSet()
custom init-method
PostInitialization
Disposable Bean's destroy
Custom destroy method
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is Spring MVC?

A

Spring Web MVC is a model-view-controller web framework built on the Servlet API. This framework is useful for creating flexible web applications to handle HTTP requests from clients. Packaging for Spring MVC projects will be war packaging.

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

What is the Dispatcher Servlet?

A

The Spring MVC web framework is designed around the front controller pattern where a central servlet, the DispatcherServlet, provides a shared algorithm for request processing, while actual work is performed by configurable delegate components. This model is flexible and supports diverse workflows.

The DispatcherServlet, as any Servlet, needs to be declared and mapped according to the Servlet specification by using Java configuration or in web.xml. In turn, the DispatcherServlet uses Spring configuration to discover the delegate components it needs for request mapping, view resolution, exception handling, and more.

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

What is Spring AOP?

A

The Spring Framework has its own Aspect-Oriented Programming framework, which is based on AspectJ. Aspect-oriented Programming (AOP) complements Object-oriented Programming (OOP) by providing another way of thinking about program structure. The key unit of modularity in OOP is the class, whereas in AOP the unit of modularity is the aspect.

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

What is an Aspect?

A

A modularization of a concern that cuts across multiple classes. Transaction management is a good example of a crosscutting concern in enterprise Java applications. In Spring AOP, aspects are implemented by using regular classes (the schema-based approach) or regular classes annotated with the @Aspect annotation (the AspectJ style).

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

What is a Join Point?

A

A point during the execution of a program

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

What is an Aspect?

A

Action taken by an aspect at a particular join point. Different types of advice include “around”, “before”, and “after” advice.

17
Q

What is a Pointcut?

A

A predicate that matches join points. Advice is associated with a pointcut expression and runs at any join point matched by the pointcut.

18
Q

What is Spring Boot?

A

Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can “just run”. It takes an opinionated view of the Spring platform and third-party libraries so you can get started with minimum configuration.

19
Q

What are the advantages of Spring Boot?

A

Embedded Tomcat, Jetty or Undertow directly (no need to deploy WAR files)

Provide opinionated ‘starter’ dependencies to simplify your build configuration

Automatically configure Spring and 3rd party libraries whenever possible

Provide production-ready features such as metrics, health checks and externalized configuration that can be exposed using Actuator

Absolutely no code generation and no requirement for XML configuration