Spring Boot Interview Questions and Answers
Freshers / Beginner level questions & answers
Ques 1. What is Spring Boot?
Spring Boot is an open source Java-based framework used to create a microservice. It is developed by Pivotal Team and is used to build stand-alone and production ready spring applications.
Ques 2. Why to use Spring Boot?
- It provides a flexible way to configure Java Beans, XML configurations, and Database Transactions.
- It provides a powerful batch processing and manages REST endpoints.
- In Spring Boot, everything is auto configured; no manual configurations are needed.
- It offers annotation-based spring application.
- Eases dependency management.
- It includes Embedded Servlet Container.
- Creates production ready microservices.
Ques 3. Mention some advantages of Spring Boot.
- Helps you to create a stand-alone application, which can be started using java.jar.
- It offers pinpointed started POMs to Maven configuration.
- Allows you to Embed Undertow, Tomcat, or Jetty directly.
- Helps you to configure spring whenever possible automatically.
Ques 4. How to create a Spring Boot application using Spring Initializer?
It is an web application provided by Spring on its official website. However, you can also create Spring Boot project by entering project details.
Ques 5. What are the ways to create Spring Boot project?
- Using Spring.io initializer.
- Using Eclipse or any similar IDE and Maven simple project.
- Using Spring Tool Suite.
- Using CLI.
Ques 6. What are the advantages of microservice?
- It makes development fast and easy.
- Compatible with all container.
- Reduce production time.
- It is a lightweight model that supports a major business application.
Ques 7. Explain different types of dependency injection.
- Constructor based dependency injection: It is a technique in which one class object supplies the dependency of another object.
- Setter-based dependency injection: It is a dependency injection in which the framework injects the primitive and string-based values using setter method.
Ques 8. What are the commands to run and stop Spring Boot executable jar file?
java -jar
$ java -jar spring-boot-sample-0.0.1-SNAPSHOT.jar
Press ctrl+C
Ques 9. What is the process that you need to follow to run Spring Boot application on the custom port?
In order to run a Spring Boot application, you require to put server.port property in application.properties.
Ques 10. Can you use Spring Boot with applications which are not using Spring?
No, it is not possible as Spring Boot is limited to Spring application only.
Ques 11. What is the name of the configuration file which you can use in Spring Boot?
The configuration file used in Spring Boot projects is called application.properties. It is an important file which allows you to override your default configurations.
Ques 12. How are properties defined in Spring Boot and where?
database.host=localhost
Ques 13. Explain @RestController annotation in Spring Boot?
Ques 14. Where can you define properties in Spring Boot application?
You can define properties of Spring Boot into a file called application.properties. It helps you to create this file manually, or you can use Spring Initializer to create this file.
Ques 15. What are the Spring Boot properties?
Spring Boot offers various properties which can be specified inside our project’s application.properties file. It helps you to set values like a server-port number, database connection configuration, etc.
Ques 16. Explain Auto-Configuration in Spring Boot.
Auto-configuration is used to configure Spring application automatically based on dependencies of classpath parameter. It makes development faster and easier.
Ques 17. How to enable logging in Spring Boot?
In order to enable debug logging, you can specify --debug while starting the application from the command prompt.
Ques 18. Explain overriding default properties in Spring Boot application.
Spring Boot has lots of properties that can be easily overridden by specifying them in application.properties.
Ques 19. What is the default package in Spring Boot?
A class without any package declaration is considered as a default package.
Most helpful rated by users:
- What is Spring Boot?
- How to scan all the beans and package declarations in Spring Boot?
- What are embedded containers support by Spring?
- What are the advantages of microservice?