Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

What are the uses of @RequestMapping and @RestController annotations in Spring Boot?

Answer»
  • @RequestMapping:
    • This provides the routing information and informs Spring that any HTTP request matching the URL must be mapped to the RESPECTIVE method.
    • org.springframework.web.bind.ANNOTATION.RequestMapping has to be imported to use this annotation.
  • @RestController:
    • This is applied to a class to mark it as a request handler thereby creating RESTful web SERVICES using Spring MVC. This annotation ADDS the @ResponseBody and @Controller annotation to the class.
    • org.springframework.web.bind.annotation.RestController has to be imported to use this annotation.

Check out more Interview Questions on Spring Boot here.

2.

Can the default web server in the Spring Boot application be disabled?

Answer»

Yes! APPLICATION.properties is used to CONFIGURE the WEB application type, by MENTIONING spring.main.web-application-type=none.

3.

How to disable specific auto-configuration class?

Answer»
  • You can use the EXCLUDE attribute of @EnableAutoConfiguration for this purpose as SHOWN below:
@EnableAutoConfiguration(exclude = {InterviewBitAutoConfiguration.class})

If the class is not specified on the classpath, we can specify the fully qualified NAME as the VALUE for the excludeName.

//By using "excludeName"@EnableAutoConfiguration(excludeName={Foo.class})
  • You can add into the application.properties and multiple CLASSES can be added by keeping it comma-separated.
4.

Can you tell how to exclude any package without using the basePackages filter?

Answer»

We can use the exclude attribute while USING the ANNOTATION @SpringBootApplication as follows: 

@SpringBootApplication(exclude= {Student.CLASS})PUBLIC class InterviewBitAppConfiguration {}
5.

Can we change the default port of the embedded Tomcat server in Spring boot?

Answer»
  • Yes, we can change it by using the application properties file by adding a PROPERTY of server.port and assigning it to any port you wish to.
  • For EXAMPLE, if you want the port to be 8081, then you have to mention server.port=8081. Once the port number is mentioned, the application properties file will be AUTOMATICALLY loaded by Spring Boot and the specified configurations will be APPLIED to the application.
6.

What are the possible sources of external configuration?

Answer»
  • Spring Boot allows the developers to run the same application in DIFFERENT environments by making use of its feature of external configuration. This uses environment variables, properties files, command-line ARGUMENTS, YAML files, and system properties to mention the required configuration properties for its corresponding environments. Following are the sources of external configuration:
    • Command-line properties – Spring Boot provides support for command-line arguments and CONVERTS these arguments to properties and then adds them to the set of environment properties.
    • Application Properties – By DEFAULT, Spring Boot searches for the application properties file or its YAML file in the current directory of the application, classpath root, or config directory to load the properties.
    • Profile-specific properties – Properties are loaded from the application-{profile}.properties file or its YAML file. This file RESIDES in the same location as that of the non-specific property files and the {profile} placeholder refers to an active profile or an environment.
7.

What is Spring Boot dependency management system?

Answer»
8.

What are the effects of running Spring Boot Application as “Java Application”?

Answer»
9.

What does @SpringBootApplication annotation do internally?

Answer»

As per the Spring Boot documentation, the @SpringBootApplication annotation is one point replacement for USING @Configuration, @EnableAutoConfiguration and @ComponentScan ANNOTATIONS alongside their default attributes.

This ENABLES the developer to use a single annotation instead of using multiple annotations THUS lessening the LINES of code. However, Spring provides loosely coupled features which is why we can use these annotations as per our project needs.

10.

What are the features of Spring Boot?

Answer»
  • Spring Boot CLI – This allows you to Groovy / Maven for writing Spring boot application and avoids boilerplate code.
  • Starter Dependency – With the help of this feature, Spring Boot aggregates common dependencies together and EVENTUALLY improves PRODUCTIVITY and reduces the burden on
  • Spring INITIALIZER – This is a web application that helps a developer in creating an INTERNAL project structure. The developer does not have to manually set up the structure of the project while making use of this feature.
  • Auto-Configuration – This helps in loading the default configurations according to the project you are working on. In this way, unnecessary WAR files can be avoided.
  • Spring Actuator – Spring boot uses actuator to provide “Management EndPoints” which helps the developer in going through the Application Internals, Metrics etc.
  • Logging and Security – This ENSURES that all the applications made using Spring Boot are properly secured without any hassle.
11.

Differentiate between Spring and Spring Boot.

Answer»
  • The Spring Framework provides multiple features like dependency injection, data BINDING, aspect-oriented programming (AOP), data access, and many more that help easier development of web applications whereas Spring Boot helps in easier USAGE of the Spring Framework by simplifying or managing various loosely coupled blocks of Spring which are tedious and have a potential of BECOMING messy.
  • Spring boot simplifies commonly USED spring dependencies and runs applications straight from a command line. It ALSO doesn’t require an application container and it helps in monitoring several components and configures them externally.
12.

Explain the advantages of using Spring Boot for application development.

Answer»
  • Spring BOOT helps to CREATE stand-alone applications which can be started using java.jar (Doesn’t require configuring WAR FILES).
  • Spring Boot also offers pinpointed ‘started’ POMs to Maven configuration.
  • Has provision to embed Undertow, Tomcat, Jetty, or other web servers directly.
  • Auto-Configuration: Provides a way to automatically configure an APPLICATION BASED on the dependencies present on the classpath.
  • Spring Boot was developed with the intention of lessening the lines of code.
  • It offers production-ready support like monitoring and apps developed using spring boot are easier to launch.
13.

What do you understand by the term ‘Spring Boot’?

Answer»

Spring Boot is an open-source, java-based FRAMEWORK that provides support for RAPID APPLICATION Development and gives a PLATFORM for developing stand-alone and production-ready spring applications with a need for very few configurations.