r/learnjava • • Apr 26 '21

Is Java Spring and Spring Boot the same thing ?

Hello, everyone.

So I am currently learning Java and I am thinking of learning Spring, But I am confused about it.

From what I understand there is Spring and Spring Boot , but they are used for the same things.

Is there any difference betwean them or is Spring Boot just a fullname and Spring is just used because it is shorter ?

54 Upvotes

22 comments sorted by

59

u/[deleted] Apr 26 '21

In the very core they are the same, but Java Spring needs much more configurations to be able to work properly. Spring Boot on the other hand works out of the box, has a local server already set up and the configurations you have to add to it are minor. If you are new to web programming on Java I would suggest to use Spring Boot with some template engine. That way you will get hands on experience and can use Java Spring confidently in future.

4

u/Hiluminatull Apr 26 '21

Cheers bro, this really helps

2

u/[deleted] Apr 26 '21

No problem, good luck!

4

u/willdrr17 Apr 26 '21

I would suggest that you learn Spring first, then you will know what kind of problem Spring Boot solves. Who knows, you may end up maintaining a legacy Spring application that uses XML configuration. See Spring 4th edition, there is also a newer version; Spring 6th edition(MEAP edition)

14

u/[deleted] Apr 26 '21

While I do get your point and you are right in your own way, I still think that he should start with easier one in the beginning of the journey. If he tries to grasp the whole Spring framework he can end up getting overwhelmed (almost happened to me). With hands on experience on Spring Boot and seeing how what you created works almost immediately - you will have both motivation and understanding. Then again, to each their own. Some people are quick learners and get everything with a flick. Some prefer slow approach (I am one of them).

6

u/qelery Apr 26 '21

While I do get your point and you are right in your own way, I still think that he should start with easier one in the beginning of the journey. If he tries to grasp the whole Spring framework he can end up getting overwhelmed (almost happened to me).

This was my recent experience. Starting off with Spring involved hours of configurations, and trying to get even a general sense of what each configuration does took even more time. At least with Spring Boot I can get something up and running, and then pick through the docs to learn about the configurations in small pieces.

5

u/[deleted] Apr 26 '21

Exactly my point. I also started to try to learn Spring first and Spring Boot afterwards and when I started to get frustrated, my teacher stopped me and pointed in the right direction. I was also cocky at that time and thought I can get it all in no time :D. Glad I was humbled.

3

u/willdrr17 Apr 26 '21

Yeah, that's true. OP should know that Spring it's more about configuration and Spring Boot it's more about conventions

3

u/nutrecht Apr 27 '21

That just makes it look like you haven't used Spring in production. Spring Boot is just preconfigured Spring. It's just a set of starters with sensible configuration defaults.

1

u/willdrr17 Apr 27 '21

You are right, I have only played with both of them. I know that Spring it's moving towards the Spring Boot way (via more annotations if not mistaken). I was suggesting to know how to configure a Spring application the old way, and it's valuable knowledge to know, there is nothing harmful about it, maybe I'm just antiquated. I did not mean to give a bad advice

2

u/nutrecht Apr 27 '21

I would suggest that you learn Spring first

IMHO this is a damaging and unhelpful suggestion for beginners.

15

u/qelery Apr 26 '21

From what I understand, Spring is giant framework that you can use to create almost any program you want, but it's mainly used for web development. Spring itself is can be broken down into small projects/modules/pieces like Spring Security, Spring Web, Spring Web, etc. So Spring is huge.

A Spring Boot project is basically an opinionated Spring project. It takes care of a lot of the configuration boiler plate using whatever are considered the most common configurations. You can always override those configurations later.

https://www.baeldung.com/spring-vs-spring-boot

13

u/[deleted] Apr 26 '21 edited Apr 27 '21

Let me illustrate the difference between the Spring Framework and Spring Boot.

Assuming you're using Maven for config.

Here's what you have to do to create a Spring Web application running in the Jetty embedded web server with MySQL. You have to specify everything you need. You have to figure out how to deploy this (a bunch of JARs or an uber-JAR?). You're on your own for configuration. But! You'll build probably the tiniest Spring program possible and start up will be lighting fast! The Spring Framework has few opinions about how you should use it. On the downside, this means you have to do more configuration. On the other hand, the Spring Framework will pretty much let you do whatever you want. Including very stupid things!

This is how I've used the Spring Framework for most of my career.

<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>5.3.6</version>
    </dependency>

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-slf4j-impl</artifactId>
        <version>2.14.1</version>
    </dependency>

    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.6</version>
    </dependency>

    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-servlet</artifactId>
        <version>10.0.2</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>5.3.6</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.23</version>
    </dependency>
</dependencies>

And you'll have to set up Jetty yourself;

public class Application {
    public static void main(String[] args) throws Exception {
        Server server = new Server();
        ServerConnector connector = new ServerConnector(server);
        connector.setPort(8080);
        server.addConnector(connector);

        ServletContextHandler contextHandler = new ServletContextHandler();
        AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
        ctx.register(AppConfig.class);
        DispatcherServlet dispatcherServlet = new DispatcherServlet(ctx);
        ServletHolder servletHolder = new ServletHolder("mvc-dispatcher", dispatcherServlet);
        contextHandler.addServlet(servletHolder, "/*");
        server.setHandler(contextHandler);

        server.start();
    }
}

With Spring Boot, Spring has everything figured out. You don't need to manually list everything you need. All you have to do is add the "starters" for the things you want, and Spring will figure out the rest. They've figured out deployment for you (uber-JAR). They've got your app config ready to go (application.yml). But there's a price. Spring Boot is a lot heavier than the Spring Framework by itself. You're probably pulling in more JARs than you actually need. Spring Boot has strong opinions. Don't argue with Spring Boot, or you will have a bad time.

I mostly go with Spring Boot these days. It's a lot faster to get a project up and running. Even the the result is more "bloated" than putting it all together by hand.

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.4.4</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jdbc</artifactId>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.23</version>
    </dependency>
</dependencies>

And super easy startup:

@SpringBootApplication
public class Application {
    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args):
    }
}

7

u/[deleted] Apr 26 '21 edited Apr 26 '21

To add something others have not said. Check out maven first before getting into Spring. It won't take much time at all but it will help you have a more immediate understanding of what spring boot actually does. That's because in Java (and programming in general), when you're using someone else's code (a framework or a library), you need to bundle up these dependencies somehow. There are a few ways to do so, but I'd say maven is the most popular.

Springboot uses a configuration tool like maven to give you a few dependencies that fall under the "spring framework" label together at once, so you can start building your project immediately, instead of spending a long time manually bundling your dependencies together. Maven basically works this way: you describe and list your dependencies to it using an xml file, and it modifies your project and file structure to include your imported code. I recommend starting with Java brains' (on YouTube) maven tutorial then jumping to his spring boot videos

4

u/yabbay12 Apr 26 '21

this question was asked to me in interview I wish I encounter like this question before

4

u/nutrecht Apr 27 '21

It's "Spring" and not "Java Spring".

Spring Boot is just a set of 'starters' that preconfigure a lot of stuff for you with sensible defaults. It's also become the de facto way of doing Spring in newer projects. So when you're learning "Spring Boot" you're just learning Spring. Hence the name, it lets you "Bootstrap" your project faster.

So Spring Boot is kinda a separate thing (because it was added later) but nowadays the distinction is almost moot.

And please don't listen to people claiming you should learn Spring before Spring Boot. I've been a Java dev for close to 20 years and it's completely pointless to take that route.

3

u/luki30210 Apr 26 '21

Spring Boot is set of configurations. You can create project with some Spring Boot Starters (ex. Web) and app will just start. Spring Boot uses traditional Spring Framework (as dependency), but you don't have to be bothered by this. At least not at the begining of development.

2

u/joranstark018 Apr 26 '21

Spring Framework (or just Spring for short) is a collection of projects, some projects provides core framework functionality (ie Spring IoC Container) some provides some higher abstraction (ie Spring MVC). Spring Boot combines different Spring Framework projects, some third-party libraries with a suitable configuration (by providing different "starter" projects), in order to make it easy to setup a new project with minimal configuration.

2

u/FilsdeJESUS Apr 27 '21

Spring is a house and there is multiple rooms and Boot is one of them , there is Cloud , MVC , Security etc . And so when you are doing Spring you should precisely tell which room you are currently using , Spring => house and Boot => the room where I am so you are doing Spring Boot

2

u/nutrecht Apr 27 '21

Spring is a house and there is multiple rooms and Boot is one of them

That's a bad analogy. There are Spring Boot starters for all the things you mentioned.

2

u/FilsdeJESUS Apr 27 '21

Yes there is a starter for all the technology , like you said there is a Spring boot Starter for all I have mentioned but the fact that these concepts remains rooms , when we do Spring you can not define Spring MVC the way you define Spring Cloud , this is what I think perhaps

0

u/[deleted] Apr 27 '21

[deleted]

2

u/[deleted] Apr 27 '21

Yes, there are "starters" for each of those.