SB-NG Flashcards

1
Q

Auto-configuration

A

When configuring your Spring Boot application, it downloads all the dependencies needed to run your application

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

Opinionated approach

A

Spring Boot uses a narrow approach to installing dependencies based on your application’s needs. Manual configuration is removed as it adds the packages you need for your application.

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

Spring starters:

A

We can choose a list of starter dependencies to define your application’s expected needs during the initialization process. One example is Spring Web, which allows us to initialize a Spring-based web application.

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

SB: Presentation/display layer

A

The presentation layer is responsible for interpreting JSON parameters as objects. This layer is the upper layer that is also responsible for handling authentication and HTTP requests. After accomplishing JSON translation and authentication, we will now move to the business layer.

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

SB: Business layer:

A

The business layer, as the name suggests, handles all the business logic in the application. It is composed of service classes that perform authorization and additional validation.

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

Persistence layer

A

The persistence layer is mainly responsible for storage logic that converts objects from and to database rows to insert data.

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

Database layer

A

The database layer performs Create, Read, Update, and Delete (CRUD) operations. The layer can consist of multiple databases.

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

Inversion of Control (IoC)

A

the concept of inverting the flow of your program, and it is used for decoupling the components in your application, making your piece of code reusable and modular

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

Constructor-based dependency injection

A

can be achieved by creating an object class with a constructor, with arguments of a specific type representing the dependency we can set.

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

Beans.xml

A

main configuration file for our construction-based injection, which is where we will define our beans together with their dependencies.

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

Spring: @Configuration

A

used to mark a class as a source of bean definitions

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

Spring: @ComponentScan

A

makes Spring scan the packages configured with it for the @Configuration classes

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

Spring: @Import

A

loads additional configuration. Works even when you specify beans in XML file

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

Spring: @Component

A

turns the class into a Spring bean at the auto-scan time

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

Spring: @Service

A

tells Spring that it’s safe to manage @Components with more freedom than regular components

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

Spring: @Autowired

A

wires the application parts together, on the fields, constructors, or methods in a component

mainly used to inject dependencies without the use of constructors and setter methods

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

Spring: @Bean

A

specifies a returned bean to be managed by Spring context. Returned bean has same name as factory method

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

@SpringBootApplication

A

uses @Configuration, @EnableAutoConfiguration and @ComponentScan

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

SB: @EnableAutoConfiguration

A

make Spring guess the configuration based on the classpath

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

SB: @Controller

A

marks the class as web controller, capable of handling the requests

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

SB: @RestController

A

a convenience annotation of a @Controller and @ResponseBody

22
Q

SB: @ResponseBody

A

makes Spring bind method’s return value to the web response body

23
Q

SB: @RequestMapping

A

specify on the method in the controller to map a HTTP request to the URL to this method

24
Q

SB: @RequestParam

A

bind HTTP parameters into method arguments

25
Q

SB: @PathVarilable

A

binds placeholder from the URI to the method parameter

26
Q

field-based dependency injection

A

s a concept where we inject the object’s dependencies directly into the fields. We will not create a constructor or a setter method to inject our dependencies, but we will use the @Autowired annotation for injection.

27
Q

are essential parts of developing your Spring applications. They are considered the building blocks of Spring and make our code less boilerplate and maintainable.

A

Annotation and beans

28
Q

are used to define the different types of beans. They are simply a form of metadata that marks our code to provide information.

A

Spring annotations

29
Q

beans

A

are objects that are instantiated and created and can be injected with other beans

30
Q

SB: @Required

A

This is applied in the setter methods of a bean and implies that the bean must be injected with the dependency at configuration. Otherwise, it will throw BeanInitializationException.

31
Q

The annotation is a class-level annotation to indicate the packages we want to be scanned for beans

A

@ComponentScan

32
Q

The annotation is a class-level annotation to indicate that a class is the source of bean definitions that the Spring container will process at runtime

A

@ComponentScan

33
Q

are mainly used to create Spring beans on the fly in an application context

A

Stereotype annotations

34
Q

Name the stereotype annotations

A

@Component
@Service
@Repository
@Controller

35
Q

@Controller

A

The annotations used for Spring controller classes. It is also a type of @Component annotation, used for Spring MVC and the methods annotated with @RequestMapping, which is used for REST.

36
Q

@Repository

A

This annotation is used for classes that directly access a database. This is an indication of a class that executes the role of a data access object.

37
Q

@Service

A

This annotation, used for the service layer, indicates that a class is used to execute business logic, perform calculations, and call external APIs. @Service is a kind of @Component annotation.

38
Q

This annotation is used to auto-configure the bean present in the classpath and then to configure it to run the methods. The annotation is now rarely used, as @SpringBootApplication has already been released in Spring 1.2.0.

A

@EnableAutoConfiguration

39
Q

@RequestMapping

A

This is used to create endpoints and map web requests. The annotations can be used in a class or a method.

40
Q

@GetMapping

A

This maps the HTTP GET requests and is used for fetching data, and it is the equivalent of @RequestMapping(method = RequestMethod.GET).

41
Q

@PostMapping

A

maps the HTTP POST requests and is used for creating data, and it is the equivalent of @RequestMapping(method = RequestMethod.POST).

&&

maps the HTTP PUT requests and is used for updating data, and it is the equivalent of @RequestMapping(method = RequestMethod.PUT)

42
Q

@DeleteMapping

A

This maps the HTTP PUT requests and is used for deleting data, and it is the equivalent of @RequestMapping(method = RequestMethod.DELETE).

&&

maps the HTTP PATCH requests and is used for partial updates on data, and it is the equivalent of @RequestMapping(method = RequestMethod.PATCH).

43
Q

@RequestBody

A

used to bind HTTP requests with an object in a method parameter. The Spring framework binds the HTTP request body of the parameter with this annotation

44
Q

@ResponseBody

A

This attaches the method’s return value to the response body. The annotation indicates that the return object should be serialized into a JSON or XML format.

45
Q

@PathVariable

A

This is used to get the values from the URI. It is allowed to define multiple @PathVariable instances in a method.

46
Q

This is used to get the query parameters from the URL.

A

@RequestParam

47
Q

CrudRepository

A

The interface repository, which provides the basic operations to Create, Read, Update, and Delete (CRUD)

48
Q

PagingAndSortingRepository

A

Extends CrudRepostiory and adds a method named findAll, which can sort results and be retrieved in a paginated manner.

49
Q

JpaRepository

A

Adds specific JPA methods and has all the functions of CrudRepository and PagingAndSortingRepository. It also adds methods such as flush(), which flushes the persistence context, and deleteInBatch(), which deletes records in a batch.

50
Q

Entity

A

This is a simple class that defines our model. It will be used as a JPA entity, generated with a primary key

51
Q

Repository

A

This is an interface that we need to extend with JPA repositories for the entities to have built-in operations.

52
Q

Where do you configure database properties? And what are these properties?

A

These properties are the server url of the database, admin username, and password and you add them to the application.properties file: i.e. spring.datasource.username=postgres