In this article
  1. The core model
  2. Configuration
  3. The Spring Framework underneath
  4. Web and data
  5. Production features
  6. Testing and startup
  7. Follow-up questions
  8. Sources

The core model

Answers follow the Spring Boot 4.1.2 build systems page and the Spring Framework 7.0.10 transaction annotations page, as of October 2026. For the wider picture of how to prepare, see coding interview preparation.

What is Spring Boot, and how does it differ from the Spring Framework?

Spring Boot is a layer on top of the Spring Framework that chooses defaults for you, so an application starts from a main method with little setup. It supplies curated dependency sets (starters), configures beans from what it finds on the classpath (auto-configuration) and bundles an embedded web server (build systems reference). The Spring Framework underneath still provides dependency injection, transactions and the web stack.

Why it is asked: it checks that you can separate the two layers. Read the full explanation: Java interview questions and answers.

What does @SpringBootApplication do?

It marks the main configuration class and combines three annotations. @SpringBootConfiguration lets the class register extra beans or import more configuration, and it is what @SpringBootTest searches for; @EnableAutoConfiguration switches on auto-configuration; @ComponentScan scans for @Component classes in the application's package (annotation reference). The reference page on structuring code advises putting the main class in a root package above your other classes because the annotation sets the base search package, for example for entities of the Java Persistence API (JPA).

Why it is asked: it is the first line of every Spring Boot project. Read the full explanation: Java interview questions and answers.

What is a Spring Boot starter?

A starter is a dependency descriptor that pulls in a consistent set of libraries for one kind of application. The build systems page gives spring-boot-starter-data-jpa as the way to get Spring and JPA database access, says official starters follow the pattern spring-boot-starter-*, and reserves the spring-boot prefix for official artifacts, so third-party starters start with their own project name.

Why it is asked: it tests whether you know why you rarely write version numbers. Read the full explanation: Java interview questions and answers.

How does Spring Boot manage dependency versions?

Each release ships a curated list of supported dependencies, published as the spring-boot-dependencies bill of materials (BOM), so you normally give no version for them (build systems reference). You can still override a version when you must. The documentation strongly recommends that you do not set the Spring Framework version yourself, because each Boot release is associated with a base Spring Framework version (build systems reference).

Why it is asked: it tests whether you can resolve a version conflict without breaking the Framework and Boot pairing. Read the full explanation: Java interview questions and answers.

How does auto-configuration work, and how do you see what was applied?

Auto-configuration sets up beans from the libraries on your classpath and the properties you set, and you opt in with @EnableAutoConfiguration or @SpringBootApplication. Its configuration classes are conditional: they apply only when certain classes are present, certain beans are not yet defined, or certain properties are set (conditions reference). For example, add your own DataSource and the default embedded database support backs away. Start the application with --debug to log a conditions report that shows what was applied and why (auto-configuration reference).

Why it is asked: it separates users of the framework from people who can debug it. Read the full explanation: Java interview questions and answers.

How do you turn off one auto-configuration?

Exclude it by class with @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }), use excludeName with the fully qualified name when the class may not be on the classpath, or set the spring.autoconfigure.exclude property. The auto-configuration reference says you can define exclusions at both levels, and that only the class name is public API.

Why it is asked: it tests control over defaults, not just acceptance of them. Read the full explanation: Java interview questions and answers.

Configuration

In what order does Spring Boot read configuration sources?

Later property sources override earlier ones. The externalized configuration page lists defaults first, then @PropertySource, then config data such as application.properties, then random.* values and operating-system environment variables, with command-line arguments near the end and test property sources and developer tools settings after them. So a command-line flag beats a file.

Why it is asked: it explains why the same jar behaves differently across environments. Read the full explanation: full stack developer interview questions.

How do properties files and YAML files interact?

Spring Boot loads both application.properties and application.yaml automatically; YAML works when the SnakeYAML library is present, which the base starter provides. If both formats sit in the same location, the external configuration documentation says .properties takes precedence, and it recommends sticking with one format for the whole application so nobody has to guess which file won.

Why it is asked: this tests whether you know which configuration source wins. Read the full explanation: Java interview questions and answers.

What is the difference between @Value and @ConfigurationProperties?

@Value("${name}") injects one property into one field. @ConfigurationProperties binds a whole prefix, such as my.service, to a typed class, and the documentation describes it as letting strongly typed beans govern and validate configuration. Use @Value for a single value and @ConfigurationProperties when several related settings travel together (external configuration reference).

Why it is asked: it tests whether your configuration will stay maintainable. Read the full explanation: Java interview questions and answers.

How do Spring profiles work?

A profile is a named set of configuration that is active only when you ask for it. Mark a @Component, @Configuration or @ConfigurationProperties class with @Profile("production"), and activate profiles with spring.profiles.active. The profiles page adds that a profile named default is used when none is active, and that profile groups switch several profiles on together.

Why it is asked: every team separates local, test and production settings. Read the full explanation: full stack developer interview questions.

Knowing it is half the job. Saying it is the other half.

Interview Clozo is an AI interview copilot for real interview rounds: it hears the question and puts a strong answer on your screen, and you say it in your own words. See the features or how it works.

Start Free Trial →

The Spring Framework underneath

Should you use constructor or setter injection?

Prefer constructor injection for required dependencies. The dependency injection reference says the team advocates it because it lets components be immutable and ensures required dependencies are not null, and it reserves setter injection for optional dependencies that have reasonable defaults. It also warns that very many constructor arguments are a smell: the class probably does too much.

Why it is asked: it reveals how you think about object design. Read the full explanation: Java object-oriented interview questions.

What is the default bean scope, and what goes wrong with a prototype inside a singleton?

A bean is an object that the Spring container creates and manages, and its default scope is singleton: one instance per container. A prototype bean injected into a singleton is created once, at injection, and that single instance is all the singleton ever receives. The scopes page points to method injection or an ObjectProvider when you need a fresh instance per call.

Why it is asked: it catches shared-state bugs before they ship. Read the full explanation: Java interview questions and answers.

How does @Transactional work, and why might it not roll back?

@Transactional works through a proxy, so only calls that arrive through the proxy are intercepted. A method calling another method of the same object does not start a transaction, even if the target is annotated. By default, a RuntimeException or Error triggers rollback and a checked exception does not (@Transactional reference).

Why it is asked: both pitfalls cause silent data bugs. Read the full explanation: Java interview questions and answers.

Web and data

How do you change the embedded server or the port?

Spring Boot's web starter includes Tomcat, and you can swap in Jetty by excluding spring-boot-starter-tomcat and adding spring-boot-starter-jetty. The Hypertext Transfer Protocol (HTTP) port defaults to 8080 and is set with server.port, or the SERVER_PORT environment variable. The how-to guide adds that server.port=0 picks a free port and -1 turns off the HTTP endpoints, which helps in tests (Spring Boot how-to).

Why it is asked: it checks you know the server is a dependency, not magic. Read the full explanation: Java interview questions and answers.

How do you handle errors in a Representational State Transfer (REST) controller?

By default Spring Boot registers an /error mapping that returns a JavaScript Object Notation (JSON) document with the status and message for machine clients. To shape the body for chosen exceptions, write a @ControllerAdvice class with @ExceptionHandler methods. Setting spring.mvc.problemdetails.enabled to true turns on problem details as defined in Request for Comments (RFC) 9457, with the application/problem+json type (servlet web reference).

Why it is asked: consistent error bodies are part of API design. Read the full explanation: full stack developer interview questions.

How does Spring Boot configure a DataSource?

You set spring.datasource.url and related properties, and Boot builds the connection pool, preferring HikariCP when it is available; the page says it is always chosen if present, and spring.datasource.type bypasses that choice. With no URL, Boot tries to auto-configure an embedded database (H2, HyperSQL (HSQL) or Derby, which the page marks deprecated) if one is on the classpath. By default, JPA tables are created automatically only for an embedded database (database reference).

Why it is asked: this tests whether you know when Boot creates a schema for you. Read the full explanation: full stack developer interview questions.

What is Open EntityManager in View, and should you keep it on?

In a web application Boot registers OpenEntityManagerInViewInterceptor by default, which keeps the persistence session open for the whole request so lazy-loaded data can be read while rendering a view. The database reference says to set spring.jpa.open-in-view to false if you do not want that. Turning it off forces you to load what a response needs inside the service layer.

Why it is asked: it probes your view of data access boundaries. Read the full explanation: full stack developer interview questions.

Production features

What is Spring Boot Actuator, and what does it expose by default?

Actuator is the production-ready feature set that adds endpoints such as health for monitoring an application. The endpoints page says that by default only the health endpoint is exposed over HTTP and Java Management Extensions (JMX). Expose more with management.endpoints.web.exposure.include; exclude wins over include. It advises securing anything exposed that could reveal sensitive information.

Why it is asked: monitoring and security meet in this one setting. Read the full explanation: full stack developer interview questions.

How is a Spring Boot application secured by default?

If Spring Security is on the classpath, web applications are secured by default, including the /error endpoint. The default user is named user, and its password is random and printed in the warning log at startup. The security page says this password is for development only and that you must change the configuration before production.

Why it is asked: it tests awareness of insecure defaults. Read the full explanation: full stack developer interview questions.

Can virtual threads be used in Spring Boot?

Yes, on Java 21 or later with spring.threads.virtual.enabled set to true. The task execution page says the auto-configured executor then becomes a SimpleAsyncTaskExecutor that uses virtual threads, and the scheduler a SimpleAsyncTaskScheduler. Without the setting, a ThreadPoolTaskExecutor with sensible defaults is used.

Why it is asked: it checks whether your knowledge is current. Read the full explanation: Java interview questions and answers.

Testing and startup

What is the difference between @SpringBootTest and @WebMvcTest?

@SpringBootTest loads the full application context, and by default (MOCK) it provides a mock web environment without starting a server; RANDOM_PORT starts a real server on a random port. @WebMvcTest is a slice: it auto-configures the Spring web framework, Model-View-Controller (MVC), and scans only controllers and similar web beans, usually with @MockitoBean standing in for collaborators (testing reference).

Why it is asked: this tests whether you can choose the narrowest test context. Read the full explanation: mocking and testing in JUnit interview questions.

What is the difference between CommandLineRunner and ApplicationRunner, and why not @PostConstruct?

Both run code after the application has started and before it accepts traffic; CommandLineRunner receives the raw string arguments and ApplicationRunner receives an ApplicationArguments object. The SpringApplication reference says startup tasks belong in these runners rather than in component lifecycle callbacks such as @PostConstruct, and @Order sets their sequence.

Why it is asked: it tests where startup logic belongs. Read the full explanation: Java for automation testing interview questions.

What does lazy initialization do, and what is its downside?

With spring.main.lazy-initialization=true beans are created when first needed rather than at startup, and @Lazy(false) opts one bean out. The SpringApplication reference lists the cost: a misconfigured bean fails later, when first used, and the Java Virtual Machine (JVM) must have memory for all beans, not only those created at startup. It is off by default.

Why it is asked: it is a trade-off question about startup time against early failure. Read the full explanation: Java interview questions and answers.

Follow-up questions

How would you write your own starter?

Write an @AutoConfiguration class with @ConditionalOnClass on the class and @ConditionalOnMissingBean on each @Bean method, so it backs away when the application defines its own bean, and list the class in META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports, the file Boot reads to find auto-configurations (creating your own auto-configuration). Then publish a starter module, which that page describes as an empty jar whose only job is to provide the dependencies. The spring-boot prefix is reserved for official artifacts, so name yours after your project, for example acme-spring-boot-starter.

How do you find out why a bean was not created?

Start the application with --debug and read the conditions report, which lists the conditions that matched and those that did not for each auto-configuration (auto-configuration reference). Then check whether a bean of your own caused the default to back away.

Which parts of the Spring Framework does Spring Boot not replace?

Boot replaces the setup, not the framework: Boot configures the container, transactions and web stack, while the Framework still does the injection, proxying and request handling. A Boot question can lead to a follow-up with the Framework mechanism underneath, as in the questions on injection, scopes and @Transactional above.

Key takeaways
  • Spring Boot adds starters, auto-configuration and an embedded server to the Spring Framework; it does not replace it.
  • Run with --debug to see which auto-configurations applied and why.
  • Later configuration sources override earlier ones, so a command-line argument beats a file.
  • Use constructor injection for required dependencies; @Transactional works through proxies and rolls back on unchecked exceptions by default.
  • Only the health endpoint is exposed over HTTP by default, and the generated security password is for development only.

Sources

  1. Using the @SpringBootApplication Annotation (Spring Boot 4.1.2 reference) — Spring (date = read date), 24 Oct 2026
  2. Auto-configuration (Spring Boot 4.1.2 reference) — Spring, VMware Tanzu (date = read date), 24 Oct 2026
  3. Externalized Configuration (Spring Boot 4.1.2 reference) — Spring (date = read date), 24 Oct 2026
  4. Endpoints (Spring Boot 4.1.2 reference, production-ready features) — Spring (date = read date), 24 Oct 2026
  5. Structuring Your Code (Spring Boot 4.1.2 reference) — Spring (date = read date), 24 Oct 2026
  6. Build Systems: starters and dependency management (Spring Boot 4.1.2 reference) — Spring (date = read date), 24 Oct 2026
  7. Profiles (Spring Boot 4.1.2 reference) — Spring (date = read date), 24 Oct 2026
  8. Testing Spring Boot Applications (Spring Boot 4.1.2 reference) — Spring (date = read date), 24 Oct 2026
  9. Embedded Web Servers (Spring Boot 4.1.2 how-to guide) — Spring (date = read date), 24 Oct 2026
  10. Constructor-based or setter-based DI (Spring Framework 7.0.10 reference) — Spring (date = read date), 24 Oct 2026
  11. Using @Transactional (Spring Framework 7.0.10 reference) — Spring (date = read date), 24 Oct 2026
  12. Bean Scopes (Spring Framework reference) — Spring (date = read date), 24 Oct 2026
  13. Spring MVC and error handling (Spring Boot 4.1.2 reference) — Spring (date = read date), 24 Oct 2026
  14. Spring Security (Spring Boot 4.1.2 reference) — Spring (date = read date), 24 Oct 2026
  15. Working with SQL Databases (Spring Boot 4.1.2 reference) — Spring (date = read date), 24 Oct 2026
  16. SpringApplication (Spring Boot 4.1.2 reference) — Spring (date = read date), 24 Oct 2026
  17. Creating Your Own Auto-configuration (Spring Boot 4.1.2 reference) — Spring (date = read date), 24 Oct 2026
  18. Task Execution and Scheduling (Spring Boot 4.1.2 reference) — Spring (date = read date), 24 Oct 2026