General Flashcards

1
Q

What does the@SpringBootApplication annotation do internally

A

The@SpringBootApplication annotation is equivalent to using
@Configuration,
@EnableAutoConfiguration, and
@ComponentScan with their default attributes.Spring Boot enables the developer to use a single annotation instead of usingmultiple. But, as we know, Spring provided loosely coupled features that we canuse for each annotation as per our project needs.

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

What is the purposeof using @ComponentScan in the class files

A

Spring Boot applicationscans all the beans and package declarations when the application initializes.You need to add the @ComponentScan annotation for your class file to scan yourcomponents added to your project

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

How does a springboot application get started

A

Just like any other Javaprogram, a Spring Boot application must have a main method. This method servesas an entry point, which invokes the SpringApplication#run method to bootstrapthe application.
@SpringBootApplication
public class MyApplication {

   public static void main(String[] args) {   
.
        SpringApplication.run(MyApplication.class);       
           // other statements     
   } }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are Starter dependencies

A

Spring boot starter is a maven template that contains a collection of all the relevant transitivedependencies that are needed to start a particular functionality.
Like we need to import spring-boot-starter-web dependency for creating a webapplication.

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web </artifactId>
</dependency>

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

Is it possible to change the port ofthe embedded Tomcat server in Spring Boot?

A

Yes, it is possible. Byusing the server.port in the application.properties.

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

Can we override or replace the Embedded tomcat server in Spring Boot

A

Yes, we can replace the Embedded Tomcat server with any server by using the Starter dependency in the pom.xml file. Like you can use spring-boot-starter-jetty as a dependency for using a jetty server in your project

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

Explain @RestControllerannotation in Sprint boot

A

It is a combination of @Controller and @ResponseBody, used for creating a restful controller. It converts the response to JSON or XML. It ensures that data returned by each method will be written straight into the response body instead of returning a template.

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

What is the differencebetween @RestController and @Controller in Spring Boot

A

@Controller Map of themodel object to view or template and make it human readable but @RestControllersimply returns the object and object data is directly written in HTTP responseas JSON or XML.

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

What is the differencebetween RequestMapping and GetMapping?

A

RequestMapping can beused with GET, POST, PUT, and many other request methods using the methodattribute on the annotation. Whereas getMapping is only an extension ofRequestMapping which helps you to improve on clarity on request.

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