Spring Boot Interview Questions for Freshers (2026): 20 Answers and REST API Example

Share this article

Updated: 16 October 2026. Preparing for a Java developer internship or an entry-level Spring Boot role? Recruiters often want to see whether you understand REST APIs, dependency injection, database access, validation and testing, not just the names of annotations. This Hiring365 guide gives 20 Spring Boot interview questions for freshers, concise explanations, a realistic practice endpoint, mistakes to avoid and a short revision plan. These are practice questions, not questions claimed to come from any particular company.

Spring Boot interview questions for freshers: quick revision map

Interview areaWhat you should be able to demonstrate
Core SpringDependency injection, beans, component scanning, Boot auto-configuration
HTTP and APIsGET/POST, path and query parameters, JSON, status codes
PersistenceEntity/DTO separation, JPA repositories, transactions
Configurationapplication.yml, profiles, environment variables
QualityValidation, service tests, API tests and backend authorization

20 Spring Boot interview questions with answers

1. What is Spring Boot?

Spring Boot is an opinionated way to build Spring applications with auto-configuration, starters and operational support. It reduces manual setup but does not replace Spring Framework. For an interview, explain one concrete benefit: adding a web starter and writing a controller without configuring every infrastructure component yourself.

2. How are Spring Framework and Spring Boot different?

Spring Framework supplies features such as dependency injection and web MVC. Spring Boot builds on Spring, choosing sensible defaults and enabling auto-configuration when the relevant dependencies and settings exist. Spring code can run without Boot; many Boot projects use Spring MVC.

3. What is dependency injection (DI)?

Instead of a class constructing every collaborator, the Spring container supplies required dependencies. Constructor injection makes collaborators explicit and simplifies isolated tests. Inject interfaces or clear abstractions where that helps design; avoid using DI merely to create many unnecessary layers.

4. What are @Component, @Service and @Repository?

They all mark classes for component scanning. @Service identifies a service-layer role and @Repository denotes a persistence-layer component and can participate in exception translation. The annotations do not automatically produce good layering; your classes still need well-defined responsibilities.

5. What does @SpringBootApplication do?

It combines configuration-related annotations including auto-configuration and component scanning. Put the application class in an appropriate root package so its component scan covers your controllers and services; otherwise explicitly configure scanning.

6. What is auto-configuration?

Spring Boot inspects dependencies, settings and defined beans and conditionally creates useful infrastructure. It backs off in many cases when you provide an explicit bean. You can inspect configuration reports rather than assuming every feature is always enabled.

7. What is a starter dependency?

A starter is a curated dependency set for a task such as web development or data access. For example, using an appropriate web starter reduces manual assembly of compatible dependencies. Choose starter names based on your project’s actual Spring Boot version and stack.

8. What is the difference between @Controller and @RestController?

@Controller typically returns views or response bodies according to annotations. @RestController combines controller behavior with response-body semantics, making it convenient for JSON APIs. It does not itself guarantee that an endpoint is secure or validates input.

9. How do @GetMapping and @PostMapping differ?

They are shortcuts for mapping HTTP GET and POST requests respectively. GET usually retrieves a resource without changing server state; POST commonly creates a resource or triggers an operation. Request semantics and status codes matter more than the annotation name alone.

10. What is @PathVariable compared with @RequestParam?

@PathVariable extracts a value from the URL path, such as /tasks/42. @RequestParam binds a query parameter such as /tasks?status=open. Choose resource identifiers versus filtering options based on your API design.

11. How is a JSON request body accepted and validated?

@RequestBody maps supported request content into a Java object. Add Bean Validation constraints and use @Valid where appropriate, then return actionable client errors for invalid payloads. Never rely on frontend validation as the only check.

12. What is a typical controller–service–repository flow?

A controller handles HTTP input and responses; a service handles business rules; a repository accesses persistent data. This separation makes tests clearer, but simple applications should avoid creating layers that only pass values through without purpose.

13. What does Spring Data JPA provide?

Spring Data JPA offers repository interfaces that reduce boilerplate for common persistence operations. JPA is the persistence API and Hibernate is a common implementation; the database still requires correct schemas, queries, indexes and transaction boundaries.

14. What is an entity versus a DTO?

An entity models a persistable domain object. A data transfer object (DTO) describes the request or response shape presented to a client. Separating them helps avoid accidentally exposing internal fields or allowing untrusted clients to update sensitive columns.

15. What is @Transactional used for?

It defines transactional behavior around suitable Spring-managed operations. A transaction can group multiple database changes so they commit or roll back together. Be careful with method visibility, internal self-calls, propagation and external services; a database transaction cannot roll back an already-sent email.

16. How should REST endpoints return errors?

Choose meaningful status codes such as 400 for invalid input, 404 for a missing resource and 409 for an applicable conflict. Return a consistent error structure with a message and safe details, and avoid leaking stack traces or credentials.

17. How are application.properties and application.yml used?

Both express configuration such as server ports, database URLs and feature toggles. Environment variables and configuration profiles help separate development and production. Never commit real tokens or passwords to a public repository.

18. What are Spring profiles?

Profiles select environment-specific bean definitions and configuration, for example development versus production. A profile is not a security boundary: do not assume setting ‘prod’ automatically protects secrets or endpoints.

19. How would you test a Spring Boot API?

Use unit tests for service rules, focused web-layer tests for controller behavior, and integration tests for database/HTTP interactions when valuable. Spring Boot offers test utilities and starter dependencies, commonly used with JUnit-based tests.

20. What is the difference between authentication and authorization?

Authentication establishes who a user is; authorization decides which actions that identity may take. Even a validly authenticated account should not automatically be allowed to edit another user’s record. Check permissions on the backend.

Spring Boot REST API example to explain in an interview

Imagine a Task Tracker API. A reader should be able to explain how a GET request is mapped, why a missing record returns 404, and where validation and persistence belong. The next fragment demonstrates endpoint mapping using a simple in-memory map; it is an educational snippet, not a complete secure production system.

import java.util.Map;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;

@RestController
@RequestMapping("/tasks")
class TaskController {
    private final Map<Long, String> tasks = Map.of(
        1L, "Revise Java collections",
        2L, "Practise SQL joins"
    );

    @GetMapping("/{id}")
    String findTask(@PathVariable long id) {
        String task = tasks.get(id);
        if (task == null) {
            throw new ResponseStatusException(
                HttpStatus.NOT_FOUND, "Task not found");
        }
        return task;
    }
}

Try GET /tasks/1 and GET /tasks/100 after placing this controller into a running Spring Boot web project. The first returns a task string; the second should result in 404. Next, replace the map with a service and repository, use response DTOs, add validation and write tests. Your best interview explanation follows the request from controller to data and back to an HTTP response.

Five scenario-based follow-up questions

  1. A request returns 500: check logs and reproduce with safe data. Is it a null value, a database outage, a serialization problem or a real bug? Never expose secrets in the response.
  2. Two clients update the same row: explain possible lost updates and why concurrency control, transaction boundaries or optimistic locking may be needed.
  3. A GET endpoint is slow: measure before optimizing, inspect query count and indexes, then add pagination or caching only if justified.
  4. An unauthenticated user can edit a task: distinguish authentication from record-level authorization and enforce permissions in the backend.
  5. A test passes locally but fails in CI: check environment configuration, timing assumptions, dependency versions and missing test data.

Seven-day Spring Boot interview preparation schedule

DayPractice outcome
1Explain beans, DI, Boot starters and auto-configuration with your own words
2Build GET, POST, PUT and DELETE endpoint routes; practise status codes
3Add request DTO validation and error handling; test invalid inputs
4Connect an in-memory database; understand entity and repository roles
5Implement one business rule in a service; write unit tests
6Add focused integration tests and document API behavior in README
7Do a 20-question mock interview and describe your design decisions

Common fresher mistakes

  • Memorising annotations without being able to explain the request flow.
  • Returning database entities directly when they contain fields the public API should not expose.
  • Putting business rules in controller methods and making the code hard to test.
  • Claiming Spring Security protects everything automatically without configuring authorization.
  • Presenting a tutorial clone as a self-designed production project.

Frequently asked questions

Is Core Java enough for a Spring Boot interview?

Core Java and OOP are essential foundations. For a Spring Boot-specific vacancy, prepare basic REST endpoints, DI, persistence and testing as well. Always prioritize skills shown on the actual job listing.

Do freshers need microservices experience?

Not automatically. A clear, tested single-service project can demonstrate stronger fundamentals than multiple half-finished microservices. Learn when separation is useful before adding complexity.

Should I memorize all 20 answers?

No. For each answer, prepare a small example from a project you built or tested. Interviewers can explore details that memorized definitions cannot cover.

Which official documentation should I use?

Start with Spring MVC request mapping, Spring Boot SQL and JPA, and Spring Boot testing. Verify examples against the versions selected for your project.

Related Hiring365 resources

Continue with our Java Spring Boot portfolio project, SQL practice questions, GitHub portfolio guide, and job-description checklist.

Editorial note: This is independently prepared practice material for Hiring365 and is not an official company question paper. Official Spring documentation was checked in October 2026. Code shown is illustrative and requires a running Spring Boot project.

Scroll to Top