Get ready for your next interview with our comprehensive question library
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.
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 APIsspring-boot-starter-data-jpa
: JPA with Hibernatespring-boot-starter-security
: Spring Securityspring-boot-starter-test
: Testing framework with JUnit, Mockitospring-boot-starter-actuator
: Monitoring and managementspring-boot-starter-data-redis
: Redis data accessspring-boot-starter-mail
: Email support@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-packagesAll are specializations of @Component
for specific layers:
@Service
public class UserService { }
@Repository
public class UserRepository { }
@Controller
public class UserController { }
Functionally similar, but provide better semantic meaning and potential for additional features.
@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);
}
}
Upgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumAccess 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