Durgesh Imp SB Questions
Durgesh Imp SB Questions
Durgesh Imp SB Questions
Q1) Is it possible to change the port of the embedded Tomcat server in Spring Boot?
Answer:
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>
<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 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.
//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
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.
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.
A) Spring has the provision of Profiles to keep the separate configuration of environments.
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.