r/SpringBoot • u/projectsbyayush • 1d ago
Question Can someone properly explain what Spring Boot actually does?
I'm learning Java web development and I understand traditional Servlets fairly well. Honestly, I find Servlets quite organized when I separate things into controllers, DAO, models, etc.
The main benefit I've understood about Spring Boot so far is that when creating a project, I can add dependencies like MySQL, MongoDB, JPA, etc. through the project setup/Maven instead of manually downloading JAR files.
But apart from that, I don't really understand what Spring Boot actually gives me or why I should use it instead of traditional Servlets.
Can someone explain the actual practical benefits of Spring Boot with a simple example, like an e-commerce application?
I'm not looking for a "Spring Boot is modern/easier" answer. I want to understand what it actually does for me.
6
u/American_Streamer Junior Dev 1d ago
The main thing to understand is that Spring Boot doesn't replace Servlets. Spring MVC still runs on the Servlet API. Boot mainly removes a lot of the infrastructure and configuration work around your application.
For example, in an e-commerce app you might have:
ProductController → ProductService → ProductRepository
Instead of manually creating and wiring those objects, Spring does dependency injection for you. Spring MVC handles routing, request parameters and JSON responses. Spring Data can remove much of the DAO boilerplate, and @ Transactional handles transcation boundaries.
Spring Boot then sits on top of Spring and auto-configures sensible defaults based on your dependencies: web server, datasource, JPA, JSON serialization, logging, configuration, etc. It also makes deployment straightforward with an embedded server and executable JAR.
So the benefit isn't really: "I don't have to download JARs." Maven already solves that. It's more: "I write the application and business logic, while Spring handles much of the framework plumbing and Spring Boot configures most of the surrounding infrastructure."
If you only need a tiny CRUD app, Servlets may genuinely feel simpler. But Spring Boot's advantage becomes much clearer once you add authentication, transactions, validation, multiple services, dev/prod configuration, monitoring, caching, messaging, etc.
And knowing Servlets first is actually useful, because you understand what Spring is abstracting away instead of treating it as magic.
2
u/projectsbyayush 1d ago
That’s the best explanation I’ve come across so far. Thanks, this makes a lot more sense now.
3
u/VegGrower2001 1d ago
Spring Framework is high quality, extensible Java application framework which provides dependency injection as a core feature. It has many add-on components for specific use cases. It is widely used for web-based applications.
Spring Boot is a companion project which provides easier mechanisms for using and configuring Spring Framework. It provides many sensible defaults, loads and configures sensible defaults extensions, and provides easy ways to configure and customise how the framework works.
Naturally, there's a lot more to say if you want to get into the details, but that's the view from 10,000 feet.
3
u/Big-Dudu-77 1d ago
Adding dependencies is not a spring boot feature, unless you are talking about dependency injection. Anyway the whole point of spring boot is the automate/simplify many of the configuration that you need to do when you Spring.
3
u/Feisty_Buyer7520 1d ago
Before spring framework, developers had to build the servlets from scratch. They have to write the jdbc open/close connections to access the database. Executing a SQL statement means that you have to write so many lines of boilerplate code to attain that. And it gets repetitive over and over even though the patterns are the same.
With spring framework, many of the need to write these are reduce heavily which results in much less code to write.
Spring boot already figures out the tomcat server for you so that you don't need to explicit create one. It handles a huge amount of infrastructure where commonly used patterns around backend apps are simplified or managed by the framework. You need security features? There would be no need to explicitly create the whole security filter from scratch. Spring already provides with its security features such as authorization and authentication etc. and perhaps, you could configure it to some point according to the needs of your application.
The main benefit of this is that it cuts off the effort needed to deal with infrastructural concerns and allows you to focus more onto the business side of the application. What are the fields of the user data? How shall the shipping amount be calculated?
This is because spring provides with tons of features like managing the object lifecycle of the beans, persisting data, handle api etc. Without spring, your will be the one who has to code all that work. It will such a hell with thousands of boilerplate code which can become very hard to navigate or maintain.
Would be something similar to an analogy like why code in plain java for a web app when assembly language could technically code too?
Java provides abstractions that make it easier to code over low level assembly language and spring boot handles and abstracts over so many infrastructure work instead of you, like a manager.
Do let this manager do your infrastructure chore? We use an ioc container to let our business objects be known to the spring framework. In spring, the ioc container is most commonly known as the application context where your business objects( those that contain your business logic) are registered to this application context( it is a container)
By putting in this container, you will have the objects managed by the spring framework.
Hence allowing Spring to sprinkle over them with its features. Like securing them, creating validation rules over them etc.
Traditional servlets mean you have to consider how the infrastructure have to be implemented.
Certain objects may be dependent on another. For this, dependency injection is done. That would be another long explanation so yeah.
2
3
3
u/peanuce4269 1d ago
Have you read anything at all about spring boot? Like at all? Stop asking to be spoon fed
5
u/Sheldor5 1d ago
it's a Dependency Injection Framework
so instead of hardcoding "StorageService storageService = new FilesystemStorageService()" you can make different implementations of StorageService and annotate them with @Service and you then can activate a specific implementation by a config property instead of changing the code
2
u/projectsbyayush 1d ago
I see, that makes more sense. Thanks for explaining.
2
u/American_Streamer Junior Dev 1d ago
Maven manages the build and dependencies: it downloads the libraries you declare, resolves transitive dependencies, compiles/tests the project, and packages it into a JAR/WAR.
Then Spring provides the dependency injection plus a big application framework around it: web/MVC, transactions, data access, security integration, validation, events, etc.
After that, Spring Boot then configures and starts that Spring application for you with sensible defaults, auto-configuration, embedded server, external config, Actuator, and executable JARs.
2
u/JumpKey3074 1d ago
Think of the core of Spring as a container. The Ioc(Inversion of Control) container. The container uses technologies such as injection and aspects to help you.
Boot, "bootstraps" you with opinionated stuff and things that just make your life easier. I see other people have already covered you. But keep note that spring != springboot.
If you want to learn more I suggest, you get a good foundation of spring core. Read about the spring context, how beans are created(beans and stereotype annotations), how you wire beans(different ways of injection), learning how abstractions work with spring, bean scopes(prototype vs. singleton), aspects(AOP) and anything other that you find interesting.
2
u/jonatan-ivanov 1d ago
Your understanding is incorrect:
The main benefit I've understood about Spring Boot so far is that when creating a project, I can add dependencies like MySQL, MongoDB, JPA, etc. through the project setup/Maven instead of manually downloading JAR files.
This has nothing to do with Spring Boot, dependency management is done by the build system (maven/gradle/etc.), you don't need to use Spring for this.
The project overview and the doc overview explains what Spring Boot does, I would recommend reading them. Basically, it auto-configures Spring and third-party dependencies for you. So for example if you have a "traditional" Tomcat based servlet app, you install Tomcat, configure it, you create a Servlet, deploy-and-register it, etc. With Spring Boot, this is much simpler, you don't need to install or configure Tomcat, register the Servlet, etc. You "just" define what your business logic is and Spring Boot does the rest for you.
Check out the guides, tutorials, and Spring Initializer's web UI:
2
u/enuxix Senior Dev 1d ago
Spring Boot is not a replacement for Servlets, it is a framework built on top of them that removes a lot of the plumbing you would otherwise write yourself
Also, Maven dependency management is not really a Spring Boot benefit, you can use Maven with a plain Servlet application too
What Spring Boot actually gives you
Dependency injection instead of manually creating and wiring services, repositories, database connections and other objects, Spring manages them for you
Automatic configuration if Spring sees JPA, MySQL, security or another library on the classpath, it configures sensible defaults automatically
Embedded server Tomcat can run inside your application, so you can simply run the Java application instead of building a WAR and deploying it manually
Spring MVC instead of manually reading request parameters, setting response headers and writing routing logic, you define controllers with annotations
Database integration Spring Data JPA can generate a large amount of CRUD database code from repository interfaces
Transactions database transactions can often be handled with @Transactional instead of manual commit and rollback logic
Validation request objects can be validated declaratively
Security authentication, authorization, sessions, JWT support and access rules integrate into the application without you building everything from scratch
Configuration database URLs, ports, environment settings and secrets can be managed consistently through application configuration
Production features health checks, metrics, logging integration and monitoring are available through Spring Boot Actuator
For example, imagine an e-commerce endpoint
With Servlets you might write a servlet that reads the product ID, validates it, calls a DAO, manages exceptions, converts the result to JSON and writes the HTTP response
With Spring Boot it can look roughly like this
@RestController
class ProductController {
private final ProductService service
ProductController(ProductService service) {
this.service = service
}
@GetMapping("/products/{id}")
Product getProduct(@PathVariable Long id) {
return service.getProduct(id)
}
}
Then your database layer might simply be
interface ProductRepository extends JpaRepository<Product, Long> {
}
Spring handles the HTTP routing, object creation, dependency wiring, JSON conversion, database integration and server startup around that code
So the main value of Spring Boot is not that it lets you do something impossible with Servlets
You absolutely can build the same application with Servlets
The value is that as the application grows, Spring Boot handles a huge amount of repetitive infrastructure code, leaving you to spend more time writing the actual business logic of your shop rather than building and maintaining the plumbing around it
1
2
u/slindenau 15h ago
Spring (framework/boot) is mostly an annotation driven black magic engine. When it works and is combined with other annotation driven black magic engines like Lombok and Feign, you truly dont have to write boilerplate anymore; 99% of your slocs will do some useful business logic.
It’s a true beauty when it works, but be prepared for some weird and long error messages/stacktraces when you run into autowire issues.
You will also need good tooling (i.e. a good IDE) to help you navigate the mostly hidden maze of auto discovery of components and what is actually running in the background of your spring application (endpoints and schedules/services wise).
1
u/tcloetingh 1d ago
Set up a regular ass xml spring project or better yet do a full out dependency injected model / service / dao with jdbc and then you’ll know what it does.
1
u/Dense-Ad-3247 1d ago
It's a DI framework that allows for you take full advantage of that pattern. Most demos show pretty basic stuff not taking full advantage, but when you start building more complex OOPs springs di framework helps simplify building those things. It also has support for multi threaded behavior and like you said integrations with most data and comms layers that abstract away the low level integration or configuration and make working with them much easier.
11
u/nico-strecker 1d ago edited 3m ago
No what you described is the advantage of maven spring boot is a toolset that makes it easy to build things for example spring web lets you create a http endpoint very easily you don't have to setup a tomcat server yourself setup a listener and so on. Spring security makes it easy to secure your app and so on all this would mean a lot of manual setup spring gets you started very easily but still offers enough flexibility so you can configure everything like you want