0% found this document useful (0 votes)
259 views5 pages

Durgesh Imp SB Questions

This document discusses questions and answers about Spring Boot. It covers topics like changing the embedded Tomcat port, replacing the embedded server, auto-configuration features, disabling auto-configuration classes, differences between controller annotations, request mapping annotations, embedded containers vs WAR files, profiles, Spring Actuator, and listing beans.

Uploaded by

subhabirajdar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
259 views5 pages

Durgesh Imp SB Questions

This document discusses questions and answers about Spring Boot. It covers topics like changing the embedded Tomcat port, replacing the embedded server, auto-configuration features, disabling auto-configuration classes, differences between controller annotations, request mapping annotations, embedded containers vs WAR files, profiles, Spring Actuator, and listing beans.

Uploaded by

subhabirajdar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Springboot durgesh notes

Q1) Is it possible to change the port of the embedded Tomcat server in Spring Boot?

Answer:

A) Yes, it is possible. By using the server.port in the application.properties.

Application.properties

Server.port=9090

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

Answer:

A) Yes, we can replace the Embedded Tomcat server with any server by using the Starter
dependency in the pom.xml file.

<dependency>

<groupId>org.springframework.boot</groupId>

<exclusions>

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

<exclusion>

</exclusion> </exclusions>

</dependency>

And now you need to include new server as a dependency i.e.:

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-jetty</artifactId>

</dependency>

Q3) What is auto-configuration in Spring boot? How does it help? Why Spring Boot is called
opinionated?

Answer:
Autoconfiguration is spring boot magic features, it automatically configures a lot of things based upon
what is present in the class path.

<dependencies>

<dependency>

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

</dependency>

<dependency>

<groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>

</dependency>

</dependencies>

Mysql dependency when you it will autoconfigure and when you add spring jpa it will also automatically
configure

Opinionated means enable and disable we can do do.

Q4) What is the difference between @SpringBootApplication and @EnableAutoConfiguration


annotation?

A) @EnableAutoConfiguration is used to enable auto-configuration but @SpringBootApplication


does a lot more than that.

It also combines @Configuration and @ComponentScan annotations to enable Java-based configuration


and component scanning in your project.

@SpringBootApplication= @Configuration + @EnableAutoConfiguration+@ComponentScan


@SpringBootApplication

Public class SpringBootAnnotationsApplication implements CommandLineRunner {

Opinionated is a software design pattern that decides or guides you into their way of doing things. Spring
Boot is opinionated because it follows the opinionated default configuration that reduces developer
efforts to configure the application.

Q5) How to disable a specific auto-configuration class?

A) We can use exclude attribute of @EnableAutoConfiguration annotation to exclude specific class.

//use of exclude

@EnableAutoConfiguration (exclude={className})

Q6) What is the difference between @RestController and @Controller in Spring Boot?

A) @Controller Map of the model object to view or template and make it human readable

@RestController simply returns the object and object data is directly written in HTTP response as JSON
or XML

@RestController = @Controller + @ResponseBody


Q8) What is the difference between @RequestMapping and @GetMapping?

A) @RequestMapping can be used with GET, POST, PUT, and many other request methods using the
method attribute on the annotation.

Whereas @GetMapping is only an extension of @RequestMapping with GET method which helps you to
improve on clarity on request.

@RequestMapping (value = “/user/{userId}”, method. RequestMethod.GET)

@GetMapping (value = “/user/{userId}”

Q9) What is the difference between an embedded container and a WAR?

A) The main difference between an embedded container and a WAR file is that you can Spring Boot
application as a JAR from the command prompt without setting up a web server.

But to run a WAR file, you need to first set up a web server like Tomcat which has Servlet container and
then you need to deploy WAR there.

Q10) What is the use of Profiles in spring boot?

A) Spring has the provision of Profiles to keep the separate configuration of environments.

Q11) What is Spring Actuator? What are its advantages?

A) Provides special feature to monitor and manage your application when you push it to
production.
<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-actuator </artifactId>

</dependency>

Through spring actuator we can enable and disable spring boot properties

Q12) How to get the list of all the beans in your Spring boot application?

A) Spring Boot actuator “/Beans” is used to get the list of all the spring beans in your application
B) “/env” returns the list of all the environment properties of running the spring boot application.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy