Master Spring Boot: Key Differences, Starters, and Advanced Configurations
This article compiles essential Spring Boot interview questions covering its distinction from Spring, Maven setup, starter modules, disabling and registering auto‑configurations, conditional beans, packaging as JAR/WAR, startup logic, external configuration sources, testing nuances, and the powerful Actuator monitoring features.
Since Spring Boot was introduced it has become a hot topic in the industry, with many companies adopting it and it frequently appearing in interview questions. Below is a curated set of Q&A to help you master Spring Boot.
What is the difference between Spring and Spring Boot?
Spring Framework offers many features such as dependency injection, data binding, aspect‑oriented programming, and data access, but over time it has grown complex and requires extensive configuration. Spring Boot applies the "convention over configuration" principle, providing starter dependencies and auto‑configuration to dramatically simplify development.
How to set up a Spring Boot application with Maven?
Include the spring-boot-starter-parent as the parent in pom.xml and declare the required starter dependencies. This reuses Spring Boot’s default settings. If a company mandates a standard BOM, you can inherit that BOM instead and add the starters under the dependencies section.
What are Spring Boot starters?
Starters manage dependencies and provide one‑stop support for specific Spring technologies. Official starters are under the org.springframework.boot package and start with spring-boot-starter-. Common starters include:
spring-boot-starter : core starter with auto‑configuration, logging, and YAML support.
spring-boot-starter-aop : AOP support with AspectJ.
spring-boot-starter-data-jpa : Spring Data JPA and Hibernate.
spring-boot-starter-jdbc : JDBC with HikariCP connection pool.
spring-boot-starter-security : Spring Security.
spring-boot-starter-test : Testing utilities.
spring-boot-starter-web : Spring MVC for web and RESTful services.
How to disable specific auto‑configuration?
Use the @EnableAutoConfiguration annotation with the exclude attribute, or the @SpringBootApplication annotation which includes it as a meta‑annotation. You can also set the spring.autoconfigure.exclude property in application.properties:
How to register custom auto‑configuration?
Create a META-INF/spring.factories file and add your configuration class under the EnableAutoConfiguration key. Place this file in src/main/resources/META-INF when using Maven.
How does Spring Boot load beans conditionally?
Use the @Conditional family of annotations, such as @ConditionalOnMissingBean, on @Bean methods. The condition checks the bean type (value) or name before creating the bean.
How to package a Spring Boot web application as JAR and WAR?
Use the spring-boot-maven-plugin to build an executable fat JAR. Ensure packaging is set to jar in pom.xml. To build a WAR, change packaging to war and exclude container dependencies.
How to run custom logic at Spring Boot startup?
Implement ApplicationRunner or CommandLineRunner and override the run method.
What external configuration sources does Spring Boot support?
Spring Boot can read configuration from command‑line arguments, application.properties or YAML files, environment variables, system properties, and profile‑specific files. Values can be injected via @Value, @ConfigurationProperties, or the Environment abstraction.
Command‑line arguments (e.g., -server.port=8080).
Application properties from application.properties or application.yml in the current directory, classpath root, or config sub‑directory.
Profile‑specific properties from application-{profile}.properties or corresponding YAML files.
How does Spring Boot testing differ from plain Spring?
Tests require an ApplicationContext. Spring Boot provides @SpringBootTest to create the context based on the classes specified in the classes attribute or by locating the main configuration class annotated with @SpringBootApplication or @SpringBootConfiguration. When using JUnit 4, annotate the test class with @RunWith(SpringRunner.class).
What is Spring Boot Actuator and why use it?
Actuator adds monitoring and management endpoints (health, metrics, env, info, etc.) accessible via HTTP or JMX. It integrates with external monitoring systems (Prometheus, DataDog, New Relic, etc.) through Micrometer. To enable it, add the spring-boot-starter-actuator dependency.
Common Actuator endpoints include auditevents, env, health, httptrace, info, metrics, mappings, scheduledtasks, threaddump, and beans. In production, protect these endpoints to prevent unauthorized access.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
