r/javahelp • u/[deleted] • Sep 29 '21
Unsolved Can someone explain to me the difference between Spring, Spring MVC and Spring Boot?
Can somebody just give me an idea as to what all things come under Spring, Spring MVC and Spring Boot, so that I can look up and try to learn things on my own. It would help me a lot if you can list out the individual things that each include. I am just starting out and I am very confused by these 3 terms. I have searched so many websites but their definitions and differences are very confusing. It didn't give me a clear understanding of these things. Also if you could suggest any good resources to start learning spring boot it would help me a lot.
22
Sep 29 '21
In a very condensed nutshell:
Spring is an umbrella project for many many libraries, all of which derive from Spring Core.
Spring Core is a dependency injection framework for Java. It is the foundation for other various frameworks in the Spring family.
Spring MVC is a web app framework built on top of Spring Core and Java Servlet API. It leverages the Model - View - Controller architecture (hence the name).
Spring Boot is another framework from this family for building web apps with less manual configurations and in less time.
5
Sep 29 '21
Essentially this. Just one clarification
Spring Boot is a configuration tool for all the spring family, not just Spring MVC.
It provides a set of opinionated defaults for pretty much everything, hiding them from the developer (except if you need/want to change those defaults).
That's why I don't recommend to learn just Spring Boot, it makes a lot of magic under the hood.
1
Sep 29 '21
Can you pleas explain what do you mean by configuration here and opinionated defaults? I have read these terms everywhere and I still couldn't get it.
3
u/ndm250 Sep 29 '21
There's a million ways to do something. When you use something that is opinionated, you are using something in a way that someone else thinks is best or at least best for most people. Opinionated defaults = the agreed upon configuration that was determined to work for most projects
1
Sep 29 '21 edited Sep 29 '21
First on configuration tool.
On the older days, Spring was configured with XML files. For even a middle-to-small project that meant huge files, hard to read and maintain.
You needed to declare every bean to be injected.
Eventually all this configuration process was enabled on code with annotations and configuration classes. But still, you needed to write a good chunk of code in order to bring it up, and most of this configurations were boilerplate, almost always the same.
Enter Spring Boot and the starters.
The starters are preconfigurations you can load, saving you a lot of tedious work. There are even third party starters.
That's why I call it a configuration tool.
Now, about it being opinionated.
All these configurations are not sacred, just handy. Most of time they will work out of the box, but some choices are made for you. That's why they mean by opinionated.
But Spring is pretty open, if you need or want to change something, there's always a way to do it.
Edit. I think I answered to the wrong post. Sorry, I'm using a new app. This was meant to u/JaneDoel
1
1
Sep 29 '21
What exactly are these configurations? In spring boot there is pom.xml which have a lot of dependencies and I think by dependency we mean jar files here? Am I right in assuming that? I have seen some small spring boot projects where mysql jar and spring data jpa was included too. I thought that spring-boot-starter-data-jpa provided the Java persistence and mysql-connector-java was to connect to the DB. And there were other jars too like spring starter web , I am not sure what's the purpose of that dependency.
And do we also consider application.properties files as one of the configuration files(where database connection details are mentioned)?
1
u/GuyWithLag Sep 29 '21
With the term "configuration" we usually mean the set of different properties that need to be set with concrete values for an application to start up. Think JDBC urls, credentials, pool sizes, buffer sizes, specific constants that you want to be able to change without rebuilding your application.
Any non-toy application usually has several different configurations: for production instances, for the test instances, for local development and testing, for the automated integration tests...
Spring makes locating, merging, and applying these configurations to the application when it starts up easier.
Spring Boot provides sensible defaults for most of it so you don't need to specify everything (it also does tons more).
1
3
u/wildjokers Sep 29 '21
There is a really nice answer here so will just add that the order you should learn things in is:
Spring core -- you must understand this or nothing else will make sense
Spring MVC -- you will almost certainly use this so after learning spring core learn this
Spring boot -- once you know core and MVC then read doc for spring boot to see what it does for you (it is a configuration framework for spring and does tons of stuff configuration wise for you).
Then any other spring libraries you need (e.g. probably will need to know Spring Data).
You could arguably switch the order you read up on MVC and Spring Boot, can't really go wrong either way.
2
Sep 29 '21
Thank you so much for the reply. Are there any good resources to learn spring core and spring mvc?
2
1
Sep 29 '21
!RemindMe 3 days
1
u/RemindMeBot Sep 29 '21 edited Sep 30 '21
I will be messaging you in 3 days on 2021-10-02 20:35:42 UTC to remind you of this link
1 OTHERS CLICKED THIS LINK to send a PM to also be reminded and to reduce spam.
Parent commenter can delete this message to hide from others.
Info Custom Your Reminders Feedback
•
u/AutoModerator Sep 29 '21
Please ensure that:
Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
You include any and all error messages in full
You ask clear questions
You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.
Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.