What Java and Spring are and how they work
Java is a language for the Java Virtual Machine (JVM): javac compiles .java files into .class bytecode, and the JVM executes it with JIT compilation and garbage collection. Spring is a family of projects for server-side Java applications: its foundation, Spring Framework, creates and wires the application’s objects, while Spring Boot configures them automatically and runs them with an embedded server.
Spring is the usual choice for services that live for years and grow with the team: REST APIs, internal enterprise systems, integrations, batch data processing. Modules are added as needed — web, data access, transactions, security, messaging. Ready-made dependency bundles are called starters, for example spring-boot-starter-webmvc for web. Spring also works with other JVM languages such as Kotlin and Groovy. For a short script or a command-line utility it is usually unnecessary: such programs need neither an IoC container nor a web server.
Every HTTP request in a Spring Boot application follows the same path. The embedded server accepts the connection, and filters — including the Spring Security filters — examine the request. DispatcherServlet, the single entry point of Spring MVC, then finds the right controller method. The controller calls a service, the service calls a repository, and Spring MVC turns the object returned by the controller into JSON.
- Embedded Tomcat accepts the connection (by default on port 8080) and passes the request to the servlet filter chain.
- The Spring Security filters check who sent the request and whether it may pass. A filter can answer on its own, and then the request goes no further.
DispatcherServletuses annotations such as@GetMappingto find a handler method and invoke it.- The controller hands the work to a service, and the service reads and writes data through a Spring Data repository.
- A message converter writes the object returned by the controller method into the response body as JSON using the Jackson library, and Tomcat sends the response to the client.
The main class and auto-configuration
The @SpringBootApplication annotation on the main class enables auto-configuration: Spring Boot looks at which libraries are among the dependencies and creates configured objects for them on its own. For example, if HSQLDB is among the dependencies and you have not declared your own DataSource, Spring Boot will start an embedded in-memory database. Any part can be replaced with your own configuration — the auto-configuration for that part then steps aside.
package com.example.shop; import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplicationpublic class ShopApplication { public static void main(String[] args) { SpringApplication.run(ShopApplication.class, args); }}How Spring Boot differs from Spring Framework
| Aspect | Spring Framework | Spring Boot |
|---|---|---|
| Role | the foundation: IoC container and dependency injection, Spring MVC, transactions, data access | a layer on top of Spring Framework: auto-configuration and running the application |
| Configuration | you describe the objects and the links between them yourself | objects for the libraries it detects are created automatically; any of them can be replaced with your own |
| Web server | the application is deployed into a servlet container, and DispatcherServlet is registered manually | the server is embedded in the application; filters and servlets are registered from Spring configuration |
Start with Spring Boot: the Spring Framework documentation recommends the same. Bare Spring Framework is needed when the application is deployed into a ready-made application server whose updates you do not control.
What to know beforehand
- The Java that Spring uses: classes, record classes, generics, exceptions, lambdas — the section “The Java that Spring uses” in this reference.
- HTTP: methods, response codes, headers — the HTTP and REST reference.
- SQL basics: tables, keys,
SELECTandJOIN— the SQL reference.
Section sources
the section is written from these pages- Spring Framework Overviewdocs.spring.io/spring-framework/reference/overview.html(opens in a new tab)
- Auto-configurationdocs.spring.io/spring-boot/reference/using/auto-configuration.html(opens in a new tab)
- Servlet Web Applicationsdocs.spring.io/spring-boot/reference/web/servlet.html(opens in a new tab)
- DispatcherServletdocs.spring.io/spring-framework/reference/web/webmvc/mvc-servlet.html(opens in a new tab)
- Architecturedocs.spring.io/spring-security/reference/servlet/architecture.html(opens in a new tab)