1. What is Spring Boot, and why is it used?
Spring Boot is an opensource framework that simplifies the development of Java applications. It’s used to quickly create production-ready, standalone Spring based applications with minimal configuration.
2. Explain the key features of Spring Boot.
Key features include autoconfiguration, embedded web servers, production-ready features, dependency management, and the Spring Boot Starter concept.
3. What are the advantages of using Spring Boot over traditional Spring Framework?
Spring Boot simplifies configuration, reduces boilerplate code, provides built-in production-ready features, and enhances development productivity.
4. How do you create a simple Spring Boot application? Can you walk me through the steps?
To create a simple Spring Boot app, you can use Spring Initializr or start with a Maven or Gradle project. Then, add dependencies and create a main class annotated with @SpringBootApplication.
5. What is the purpose of the @SpringBootApplication annotation in a Spring Boot application?
It’s a convenience annotation that combines @Configuration, @EnableAutoConfiguration, and @ComponentScan. It marks a class as a Spring Boot application entry point.
6. How does Spring Boot simplify the configuration of database connections?
Spring Boot provides autoconfiguration for common database connection properties. You only need to specify the database details in your application.properties or application.yml file.
7. What is the role of the application.properties or application.yml file in a Spring Boot project?
These files allow you to configure application properties such as database settings, server ports, and logging levels without writing extensive code.
8. How can you define custom properties in a Spring Boot application and access them in your code?
You can define custom properties in application.properties or application.yml. To access them, use the @Value annotation or inject them into a @ConfigurationProperties annotated class.
9. Explain the concept of Spring Boot Starters. Provide an example of when you would use one.
Starters are preconfigured templates for common use cases (e.g., Spring Boot Starter Web for web applications). You use them to simplify dependency management and setup.
10. What is Spring Boot AutoConfiguration, and how does it work?
AutoConfiguration automatically configures beans based on dependencies present in the classpath. Spring Boot uses conditionals to determine if a particular bean should be created.