Spring
Spring is a framework for Java and Kotlin applications that creates and connects the objects your code depends on. Spring Boot builds on it to simplify application setup and startup.
Also known as: Spring Boot
What Spring does
A backend service rarely works on its own. An order service might need a repository to store orders and a separate component to price them. With Spring Framework, the service declares what it needs, and Spring supplies those collaborators. The framework also provides infrastructure for tasks such as routing HTTP requests and managing database transactions. Spring Boot is a separate project built on Spring Framework, not another name for it.
How Spring wires an application
A bean is an object managed by the Spring container, typically accessed through an ApplicationContext. Spring learns what to manage from configuration: it can discover classes annotated with @Component or @Service, or use objects returned by @Bean methods. When creating a bean, the container can resolve its constructor parameters from other beans. This is dependency injection: the class receives the objects it needs instead of creating them itself.
@Service
class OrderService {
private final OrderRepository orders;
OrderService(OrderRepository orders) {
this.orders = orders;
}
}
If component scanning finds OrderService and the container can identify a matching OrderRepository bean, Spring passes that repository to the constructor. A single constructor does not need @Autowired. In a unit test, you can call the same constructor with a fake repository without starting Spring.
What Boot adds
Spring Boot starters group dependencies for common tasks, such as building a web API. Auto-configuration checks conditions such as which libraries are on the classpath and which beans the application already defines. That lets Boot provide defaults without forcing every project to use them. A Boot application using Spring MVC can run with an embedded web server. The same framework also works for monoliths, background workers, and batch jobs; using Boot does not make an application a microservice.
Common pitfalls and interview topics
Spring's default bean scope is singleton: one instance per bean definition in a container, not one instance of a class across the JVM. Singleton scope does not make an object thread-safe. For example, storing a request's current customer in a field on a shared service can let concurrent requests overwrite each other's data.
Another interview favorite is a method annotated with @Transactional that is called from another method on the same object. In Spring's default proxy mode, the internal call bypasses the proxy, so the called method's transaction settings are not applied. That does not mean there is no transaction: if the caller already opened one, the code can still run inside it.