Interview Questions

Get ready for your next interview with our comprehensive question library

Spring Boot Interview Questions

Filter by Difficulty

1.

Explain the difference between Spring and Spring Boot.

beginner
Aspect Spring Spring Boot
Configuration Manual XML/Java configuration Auto-configuration
Server Setup External server required Embedded server included
Dependencies Manual dependency management Starter dependencies
Deployment WAR files to external servers Executable JAR files
Development Time More setup and configuration Faster development

Spring Boot is built on top of Spring framework and provides opinionated defaults to get started quickly.

2.

What are Spring Boot Starters? Name some commonly used starters.

beginner

Spring Boot Starters are dependency descriptors that include a set of convenient dependency management for specific functionality.
Common starters:

  • spring-boot-starter-web: Web applications with REST APIs
  • spring-boot-starter-data-jpa: JPA with Hibernate
  • spring-boot-starter-security: Spring Security
  • spring-boot-starter-test: Testing framework with JUnit, Mockito
  • spring-boot-starter-actuator: Monitoring and management
  • spring-boot-starter-data-redis: Redis data access
  • spring-boot-starter-mail: Email support
3.

Explain the @SpringBootApplication annotation.

beginner

@SpringBootApplication is a convenience annotation that combines three annotations:

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

Equivalent to:

  • @Configuration: Indicates configuration class
  • @EnableAutoConfiguration: Enables auto-configuration
  • @ComponentScan: Enables component scanning in current package and sub-packages
4.

What is the difference between @Component, @Service, @Repository, and @Controller?

beginner

All are specializations of @Component for specific layers:

  • @Component: Generic stereotype for any Spring-managed component
  • @Service: Business logic layer components
  • @Repository: Data access layer components (adds exception translation)
  • @Controller: Presentation layer components for handling HTTP requests
@Service
public class UserService { }
@Repository
public class UserRepository { }
@Controller
public class UserController { }

Functionally similar, but provide better semantic meaning and potential for additional features.

5.

How do you create a RESTful web service in Spring Boot?

beginner
@RestController
@RequestMapping("/api/users")
public class UserController {
    @Autowired
    private UserService userService;
    @GetMapping
    public List<User> getAllUsers() {
        return userService.findAll();
    }
    @GetMapping("/{id}")
    public User getUser(@PathVariable Long id) {
        return userService.findById(id);
    }
    @PostMapping
    public User createUser(@RequestBody User user) {
        return userService.save(user);
    }
    @PutMapping("/{id}")
    public User updateUser(@PathVariable Long id, @RequestBody User user) {
        return userService.update(id, user);
    }
    @DeleteMapping("/{id}")
    public void deleteUser(@PathVariable Long id) {
        userService.delete(id);
    }
}
6.

What is the difference between @RequestMapping and @GetMapping?

beginner

Upgrade to Premium to see the answer

Upgrade to Premium
7.

Explain Spring Boot's embedded server concept.

beginner

Upgrade to Premium to see the answer

Upgrade to Premium
8.

What are the different ways to run Spring Boot applications?

beginner

Upgrade to Premium to see the answer

Upgrade to Premium
9.

What is the difference between @RestController and @Controller?

beginner

Upgrade to Premium to see the answer

Upgrade to Premium
10.

What are Spring Boot DevTools and how do they improve development?

beginner

Upgrade to Premium to see the answer

Upgrade to Premium
11.

What is auto-configuration in Spring Boot? How does it work?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
12.

How do you configure different environments in Spring Boot?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
13.

Explain dependency injection in Spring Boot with examples.

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
14.

What is Spring Boot Actuator and what are its key features?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
15.

How do you handle exceptions globally in Spring Boot?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
16.

What is Spring Data JPA and how do you use it in Spring Boot?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
17.

Explain the difference between @Autowired, @Inject, and @Resource.

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
18.

How do you implement validation in Spring Boot?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
19.

What are Spring Boot profiles and how do you use them?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
20.

How do you configure and use caching in Spring Boot?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
Showing 1 to 20 of 36 results

Premium Plan

$10.00 /monthly
  • Access all premium content - interview questions, and other learning resources

  • We regularly update our features and content, to ensure you get the most relevant and updated premium content.

  • 1000 monthly credits

  • Cancel anytime