Spring-Boot-201 Flashcards

1
Q

Do we require a parent tag in mvn while configuring the Boot ?

A

Yes with Mvn a tag is required

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

To which package all the boot dependncies fall on?

A

spring-boot-starters

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

How the Main class should be?

A

It should have annotated with @SpringBootApplication

Also provide the arg to SpringBootApplication.run in main method

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

What is mvnw

A

Maven wrapper, it is an automated building tool by spring boot

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

What goes in tag on pom.xml?

A

org.springframework.boot>

spring-boot-starter-parent>

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

What is a 12 factor app?

A

I. Codebase
One codebase tracked in revision control, many deploys
II. Dependencies
Explicitly declare and isolate dependencies
III. Config
Store config in the environment
IV. Backing services
Treat backing services as attached resources
V. Build, release, run
Strictly separate build and run stages
VI. Processes
Execute the app as one or more stateless processes
VII. Port binding
Export services via port binding
VIII. Concurrency
Scale out via the process model
IX. Disposability
Maximize robustness with fast startup and graceful shutdown
X. Dev/prod parity
Keep development, staging, and production as similar as possible
XI. Logs
Treat logs as event streams
XII. Admin processes
Run admin/management tasks as one-off processes

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

Can we have a yml prop also ?

A

Yes we can have yml also as prop

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

What is @SpringBootApplication composed of ?

A

@Confuguration, @ComponentScan, @EnableWebConfiguration

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

What does SprinBootaPPLICATION.RUN DOES

A

It gets to know which class is booting up

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

What is SpringApplicatioBuilder class?

A

Sometimes you require heirarchy or need multiple things to while booting up , this will help

new SpringApplicationBuilder(Main.cllass).child(otherconfig.class).run(args)

generally the weconfig goes to child part (like these)

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

How you can mute the logging info

A

new SpringApplicationBuilder(Main.class).logStraytupInfo(false).run(args);

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

How we can have profiles

A

With the same SpringApplicationBuilder use .profiles

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

How can we add listeners

A

Yes .listener and then impl the Interface like ApplicationEvent

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

How can we deliberately stop spring assuming the AutoConfiguration?

A
There are .operators like to SBApp class like :
.web(WebApplicationType.NONE)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What @Order will do ?

A

If you want to execute the Main in certain order

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

How can we provide the prop files to Main

A

We can use Or @PropertySource, use default application.prop or applicaion.yml and place it in classpath
Yes Env variable can be used also

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

How can the property be accessed in a class?

A

@Value(“${prop}”)

18
Q

How can be give the prop form cmd?

A

–prop=val Or -DProp=val

19
Q

How to use mvnw

A

mvnw spring-boot:run -Dspring.config.name=val

20
Q

What all is included in Spring web

A

Spring -web, webmvc, webflux & websocket

21
Q

What are the names of he folder for static contents

A

/static, /public, /resources, /META-INF/resources

22
Q

Can index.html server automatically?

A

Yes many of the java frameworks does that

23
Q

What flexibility do we have with JSOn and XMl in Boot?

A

Yes the JSOn HttpMessageConverter is autoadded, and if the App has JSOnXMLExtension in CPath then XML converter will be auto added

24
Q

Can we have more control about JSON to and fro processing?

A

Yes need to extend JsonSerializer Or JsonDesiriallizer and @JSonComponent.

By default Jackson is provided by Boot

25
Q

Can we change the Jacksoon default date format?

A

Yes spring.jackson.date-format=SimpleDateFormat

26
Q

Does Boot do the content negotiation by default?

A

Yes

27
Q

What is the default error page locatin ?

A

/error

28
Q

Where custom error page be created?

A

/src/main/resources/public/error : such as 55.html, 404.html, and the like

29
Q

Whic anntoations to be used for handling errors?

A

@ControllerAdvice & @ExceptionHandler

30
Q

How can custom error pages be registered?

A

By implementing ErrorPageRegistrar and declaring as Spring Bean

31
Q

Say something about @RestController?

A

The @RestController offers @Controller also , and it used for handling request mappings, request input or exception handling

32
Q

Say something about @RequestMapping ?

A

It is used for mapping the Http Methods , request params, headers and mediatypes. It can be used at class or method level

33
Q

Explain @Autowired ?

A

The autowired can be ommitted , spring 5 and above auto does it, also it is used for injecting the constrtr dependency

34
Q

Explain @PathVariable?

A

It is used for defining the variable which are coming into path , as /api/{id}, the name should match with the arg type

35
Q

@RequestBody?

A

This is used to map JSON or XMl data to a Model class.

The Boot auto does it as it auto uses MappingJackson2HttpMessageConverter

36
Q

ResponseEntity?

A

This return a full details API response with headers and the body which is converted to HttpMessageConvertors and wriiten to HTTP

37
Q

@ResponseStatus?

A

This is used generally when null is returned with a status code.

38
Q

State some of Principles of Spring FW?

A
Single Resposibility Principle(SIP)
Open Closed 
Liskov-Substituion
Interface Segregation
Dependency Inversion
39
Q

Explain SIP?

A

The SIP states that a module, class or fnction must have one resposibility & only one reason to change.

40
Q

If we do not follow SIP, what will be the impact?

A

The classes will have cyclomatic complexity & poor testability

41
Q

Explain OCP?

A

It states that class must be open for extension but closed for modification

42
Q

In Boot, how does the Context Component Scan does automatically?

A

the package of @SpringBootApplication is taken into consideration by default