General Flashcards
What does the@SpringBootApplication annotation do internally
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.
What is the purposeof using @ComponentScan in the class files
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 does a springboot application get started
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 } }
What are Starter dependencies
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>
Is it possible to change the port ofthe embedded Tomcat server in Spring Boot?
Yes, it is possible. Byusing the server.port in the application.properties.
Can we override or replace the Embedded tomcat server in Spring Boot
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
Explain @RestControllerannotation in Sprint boot
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.
What is the differencebetween @RestController and @Controller in Spring Boot
@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.
What is the differencebetween RequestMapping and GetMapping?
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.