654

I hear a lot about Spring, people are saying all over the web that Spring is a good framework for web development. What exactly is Spring Framework for in a nutshell? Why should I used it over just plain Java.

Maksim
  • 16,635
  • 27
  • 94
  • 135
  • 15
    I understand that the question is very broad, but I do think that in this very specific case the question is very important for junion developers who are often spoken about Spring by people who assume it is enough popular that there is no need to even tell what it does. After all, raise your hand if you never heard about Instagram and what its purpose is.... (confession: I never used Insta) – usr-local-ΕΨΗΕΛΩΝ Jan 17 '19 at 10:42
  • 2
    Question was asked 10 years ago, and at that time Spring was a bit smaller than now with all its sub projects, such as Spring Boot, Spring Data, Spring Rest, etc. And actually that's why it was closer a year ago, because of the broadness of this question. At the time when I asked this question I just wanted to understand DI and why it is needed. – Maksim Jan 17 '19 at 16:32

17 Answers17

740

Basically Spring is a framework for which is a pattern that allows building very decoupled systems.

The problem

For example, suppose you need to list the users of the system and thus declare an interface called UserLister:

public interface UserLister {
    List<User> getUsers();
}

And maybe an implementation accessing a database to get all the users:

public class UserListerDB implements UserLister {
    public List<User> getUsers() {
        // DB access code here
    }
}

In your view you'll need to access an instance (just an example, remember):

public class SomeView {
    private UserLister userLister;

    public void render() {
        List<User> users = userLister.getUsers();
        view.render(users);
    }
}

Note that the code above hasn't initialized the variable userLister. What should we do? If I explicitly instantiate the object like this:

UserLister userLister = new UserListerDB();

...I'd couple the view with my implementation of the class that access the DB. What if I want to switch from the DB implementation to another that gets the user list from a comma-separated file (remember, it's an example)? In that case, I would go to my code again and change the above line to:

UserLister userLister = new UserListerCommaSeparatedFile();

This has no problem with a small program like this but... What happens in a program that has hundreds of views and a similar number of business classes? The maintenance becomes a nightmare!

Spring (Dependency Injection) approach

What Spring does is to wire the classes up by using an XML file or annotations, this way all the objects are instantiated and initialized by Spring and injected in the right places (Servlets, Web Frameworks, Business classes, DAOs, etc, etc, etc...).

Going back to the example in Spring we just need to have a setter for the userLister field and have either an XML file like this:

<bean id="userLister" class="UserListerDB" />

<bean class="SomeView">
    <property name="userLister" ref="userLister" />
</bean>

or more simply annotate the filed in our view class with @Inject:

@Inject
private UserLister userLister;

This way when the view is created it magically will have a UserLister ready to work.

List<User> users = userLister.getUsers();  // This will actually work
                                           // without adding any line of code

It is great! Isn't it?

  • What if you want to use another implementation of your UserLister interface? Just change the XML.
  • What if don't have a UserLister implementation ready? Program a temporal mock implementation of UserLister and ease the development of the view.
  • What if I don't want to use Spring anymore? Just don't use it! Your application isn't coupled to it. Inversion of Control states: "The application controls the framework, not the framework controls the application".

There are some other options for Dependency Injection around there, what in my opinion has made Spring so famous besides its simplicity, elegance and stability is that the guys of SpringSource have programmed many many POJOs that help to integrate Spring with many other common frameworks without being intrusive in your application. Also, Spring has several good subprojects like Spring MVC, Spring WebFlow, Spring Security and again a loooong list of etceteras.

Anyway, I encourage you to read Martin Fowler's article about Dependency Injection and Inversion of Control because he does it better than me. After understanding the basics take a look at Spring Documentation, in my opinion, it is used to be the best Spring book ever.

starball
  • 20,030
  • 7
  • 43
  • 238
victor hugo
  • 35,514
  • 12
  • 68
  • 79
  • 152
    Whats the difference between having to change a line of code and a line of XML? The effort and maintenance hell is exactly the same, or even worse, since the external xml files arguably adds complexity? Sorry but I just dont get it, I dont see any benefit at all. Please fill me in if Im missing something. – fred Dec 30 '11 at 05:57
  • 23
    @fred - Imagine you are doing unit testing. Without dependency injection(DI can be used with annotations or with XML) you can't properly test, because you can't mock the dependencies. – Petar Minchev Dec 30 '11 at 09:32
  • 19
    @fred - defining all injection in XML indeed makes little sense. It's a massive overhead to maintain. Therefor EJB introduced the concept of annotations for injection points. Those are much simpler and a default instance will be injected (for unit tests this can be changed once). This worked so well that Spring has now copied this approach. Note that if needed (but only if really needed) annotations can still be overriden by XML in EJB. – Mike Braun Jan 12 '12 at 18:45
  • 8
    @fred Also, in the real world it would be changing one line of XML vs. a bunch of lines of code. – victor hugo May 24 '12 at 00:10
  • 37
    Or, you know, use a factory static method. Change the factory's return type, and now all of the classes that use that return value are changed. *Presto* Spring is now no longer needed... – Qix - MONICA WAS MISTREATED Nov 25 '14 at 20:04
  • 1
    great answer, but I don't think the Spring Documentation is a great book. It didn't start with the basics as you did here. It would be great if you link a better introductory to Spring. Something that shows examples as you did to explain the ideas. – Jack Twain Jan 04 '15 at 10:56
  • 1
    It used to be, almost 6 years ago when I wrote this answer (wow 6 years!) – victor hugo Jan 05 '15 at 21:24
  • 8
    @fred in this example, we see the `UserLister` object only being used once. So yes, here, it is a choice of "change one line in XML, or change one line in code". But now, imagine in a larger application that `UserLister` is being used in multiple classes / packages. Now it's obvious that you'd rather change the one line in XML than find every use of the class and change the instantiation (in potentially a dozen classes) – Don Cheadle Apr 14 '15 at 16:05
  • 17
    @mmcrae I'd rather do one refactorization call in my IDE than write XML. – Qix - MONICA WAS MISTREATED Apr 14 '15 at 16:09
  • 1
    @fred I think using a factory in this case would also lead to the same case. But without a factory if each of your view has x = new y(); then you have to go to each view and change that y to something else like z. – Prathik Rajendran M Jun 02 '15 at 11:11
  • Not the best piece of code to justify the need for a new framework. See my answer. – Ash Jun 03 '15 at 02:15
  • 3
    @mmcrae Why would you change lots of lines of code? The class instantiates the dependency, so you'd only replace one line of code for every 'different' line you'd be replacing in XML. I don't support Spring, nor contest it. – insidesin Aug 04 '15 at 10:39
  • It seems Spring dependency injection is best suited for CRUD applications – James Wierzba Sep 03 '15 at 14:35
  • Actually @victorhugo, the framework **does** control the application...you got it all wrong. – Jossie Calderon Jun 13 '16 at 05:28
  • 1
    @JossieCalderon please elaborate your comment. Otherwise I recommend you to read http://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html – victor hugo Aug 06 '16 at 14:44
  • @JamesWierzba absolutely not, it fits for anything that need dependency injection and is expect to grow. – Walfrat Dec 09 '16 at 09:16
  • 4
    Spring is good for people who don't want to spend effort to learn and think and use an api... It yields absolutely nothing and solves very little. Added complexity of having to load a tone of useless spring classes and potential memory leaks and learning to understand the framework is a deterent. I see no use for it other than just saying "yea i know how to write xml configs, hee haw" Anyways 75 up votes cannot be wrong... Spring is more or less useless library, the only reason people use it is because it's popular. Almost 10 years working with java I have yet to see a useful implementation – niken May 18 '17 at 18:41
  • @mamakin So very true... I have seen Spring used in a few real-world projects, but so far it has always clearly being used for purely political reasons - only adding unnecessary complexity, without solving any real problems or adding any flexibilty that actually got used. – Rogério Sep 08 '17 at 00:23
  • I have to add a caveat to my last comment "adds very little" and "solve nothing" are not entirely accurate statements... While it's true that spring is over-and-miss used a lot, there are places where it shines and is absolutely invaluable. One such place is transactions and eip. Spring libs give you a standard approach to orchestrating and enlisting transactions. This functionality is absolutely invaluable in certain applications... – niken Sep 08 '17 at 15:07
  • Spring is a framework that aims to reduce the complexity and helps to make a lot of things simpler to develop. In parallel with the above, it also helps to reduce the lots of boilerplate code which you couldn’t get rid of before: The necessary code which is repetitive and draws focus away from the main logic. Here are some history and approach to why spring was born: https://www.zoltanraffai.com/blog/what-is-spring-framework-in-java/ – Zoltán Raffai Jul 09 '18 at 08:02
  • Also, the guys at spring are software engineering wizards. I'm always impressed at when I read the spring code at how elegant things are. – xdhmoore Mar 21 '19 at 19:03
  • @victorhugo flawless answer! – Gaurav Jun 21 '19 at 06:18
  • In my opinion, that was only the starting point of Spring. I met one of the core-developers of Spring and their intention is a fully-comprehensive Java SE stack alternative to Java EE application development. – Erdinc Ay Sep 06 '19 at 12:59
  • 2
    > What if I don't want to use Spring anymore? Just don't use it! Your application isn't coupled to it. ah, yes, all these `@Autowired`/`@Inject`ed fields will still work without Spring putting values in place for me – c-x-berger Jul 28 '20 at 19:26
64

Spring contains (as Skaffman rightly pointed out) a MVC framework. To explain in short here are my inputs. Spring supports segregation of service layer, web layer and business layer, but what it really does best is "injection" of objects. So to explain that with an example consider the example below:

public interface FourWheel
{
   public void drive();
}

public class Sedan implements FourWheel
{
   public void drive()
   {
      //drive gracefully
   }
}

public class SUV implements FourWheel
{
   public void drive()
   {
      //Rule the rough terrain
   }
}

Now in your code you have a class called RoadTrip as follows

public class RoadTrip
{
    private FourWheel myCarForTrip;
}

Now whenever you want a instance of Trip; sometimes you may want a SUV to initialize FourWheel or sometimes you may want Sedan. It really depends what you want based on specific situation.

To solve this problem you'd want to have a Factory Pattern as creational pattern. Where a factory returns the right instance. So eventually you'll end up with lots of glue code just to instantiate objects correctly. Spring does the job of glue code best without that glue code. You declare mappings in XML and it initialized the objects automatically. It also does lot using singleton architecture for instances and that helps in optimized memory usage.

This is also called Inversion Of Control. Other frameworks to do this are Google guice, Pico container etc.

Apart from this, Spring has validation framework, extensive support for DAO layer in collaboration with JDBC, iBatis and Hibernate (and many more). Provides excellent Transactional control over database transactions.

There is lot more to Spring that can be read up in good books like "Pro Spring".

Following URLs may be of help too.
http://static.springframework.org/docs/Spring-MVC-step-by-step/
http://en.wikipedia.org/wiki/Spring_Framework
http://www.theserverside.com/tt/articles/article.tss?l=SpringFramework

bluish
  • 26,356
  • 27
  • 122
  • 180
Priyank
  • 14,231
  • 18
  • 78
  • 107
  • 6
    Spring *contains* an MVC framework. But it's a lot, lot more than that. – skaffman Jun 30 '09 at 14:19
  • Without wishing to nitpick too much, WebMVC is part of the core spring distro. Webflow, RCP et al are not. – skaffman Jun 30 '09 at 18:24
  • 1
    That's nice, I did not know that you can instantiate objects of type Interface in Java - **which is illegal** @skaffman help me understand this answer (see Instance of FourWheel) – Jossie Calderon Jun 12 '16 at 16:28
49

Old days, Spring was a dependency injection frame work only like (Guice, PicoContainer,...), but nowadays it is a total solution for building your Enterprise Application.

The spring dependency injection, which is, of course, the heart of spring is still there (and you can review other good answers here), but there are more from spring...

Spring now has lots of projects, each with some sub-projects (http://spring.io/projects). When someone speaks about spring, you must find out what spring project he is talking about, is it only spring core, which is known as spring framework, or it is another spring projects.

Some spring projects which is worth too mention are:

If you need some more specify feature for your application, you may find it there too:

  • Spring Batch batch framework designed to enable the development of
    batch application
  • Spring HATEOAS easy creation of REST API based on HATEOAS principal
  • Spring Mobile and Spring Andriod for mobile application development
  • Spring Shell builds a full-featured shell ( aka command line) application
  • Spring Cloud and Spring Cloud Data Flow for cloud applications

There are also some tiny projects there for example spring-social-facebook (http://projects.spring.io/spring-social-facebook/)

You can use spring for web development as it has the Spring MVC module which is part of Spring Framework project. Or you can use spring with another web framework, like struts2.

Alireza Fattahi
  • 42,517
  • 14
  • 123
  • 173
  • 1
    I'd actually like to see the mvc, data, jpa and other parts of Spring have an option to not use Spring's core DI, but put Dagger in the heart of Spring instead. – dlamblin Apr 03 '19 at 13:55
25

What is Spring for? I will answer that question shortly, but first, let's take another look at the example by victor hugo. It's not a great example because it doesn't justify the need for a new framework.

public class BaseView {
  protected UserLister userLister;

  public BaseView() {
    userLister = new UserListerDB(); // only line of code that needs changing
  }
}

public class SomeView extends BaseView {
  public SomeView() {
    super();
  }

  public void render() {
    List<User> users = userLister.getUsers();
    view.render(users);
  }
}

Done! So now even if you have hundreds or thousands of views, you still just need to change the one line of code, as in the Spring XML approach. But changing a line of code still requires recompiling as opposed to editing XML you say? Well my fussy friend, use Ant and script away!

So what is Spring for? It's for:

  1. Blind developers who follow the herd
  2. Employers who do not ever want to hire graduate programmers because they don't teach such frameworks at Uni
  3. Projects that started off with a bad design and need patchwork (as shown by victor hugo's example)

Further reading: http://discuss.joelonsoftware.com/?joel.3.219431.12

Ash
  • 2,021
  • 2
  • 26
  • 59
  • 12
    Frustration aside, I am wondering about your arguments. I don't know any programming tool that you can't use to produce bad design. What you aim at is that using frameworks you can make bad code do lots of stuff. That's universally true and not specific to Spring. Otherwise what's the point? Don't you think competent developers can make great use of what Spring has to offer - being particular in which tools of the framework they use? At least I am quite certain that you don't imply that no Spring developer has ever heard of extending classes. The further reading is hilarious, though. – sthzg Nov 21 '15 at 08:50
  • 2
    Furthermore, your example works because the view needs only one injected service (`UserLister`), but what if it needs several services, *not shared* between the different `BaseView`'s children? There is (fortunately) no multiple inheritance in Java. – Edouard Berthe Aug 01 '17 at 13:42
  • @EdouardBerthe Fair point. My answer was not an attempt to disregard DI, it just points out the example shown in the accepted answer is not the greatest; the scenario you are proposing would most likely work better. The point I was really trying to make is not that you don't need DI, but rather you don't need an entire framework to do it. – Ash Mar 07 '19 at 03:56
20

Very short summarized, I will say that Spring is the "glue" in your application. It's used to integrate different frameworks and your own code.

Johan
  • 335
  • 3
  • 6
16

Spring is three things.

  1. Spring handles Dependency Injection and I recommend you read Martin Fowler's excellent introduction on dependency injection.
  2. The second thing Spring does is wrap excellent Java libraries in a very elegant way to use in your applications. For a good example see how Spring wraps Task Executors and Quartz Scheduler.
  3. Thirdly Spring provides a bunch of implementations of web stuff like REST, an MVC web framework and more. They figure since you are using Spring for the first two, maybe you can just use it for everything your web app needs.

The problem is that Spring DI is really well thought out, the wrappers around other things are really well thought out in that the other things thought everything out and Spring just nicely wraps it. The Spring implementations of MVC and REST and all the other stuff is not as well done (YMMV, IMHO) but there are exceptions (Spring Security is da bomb). So I tend to use Spring for DI, and its cool wrappers but prefer other stuff for Web (I like Tapestry a lot), REST (Jersey is really robust), etc.

bluish
  • 26,356
  • 27
  • 122
  • 180
karstensrage
  • 161
  • 1
  • 2
12

What you'd probably want in a web application with Spring -

  • Spring MVC, which with 2.5+ allows you to use POJOs as Controller classes, meaning you don't have to extend from any particular framework (as in Struts or Spring pre-2.5). Controller classes are also dead simple to test thanks in part to dependency injection
  • Spring integration with Hibernate, which does a good job of simplifying work with that ORM solution (for most cases)
  • Using Spring for a web app enables you to use your Domain Objects at all levels of the application - the same classes that are mapped using Hibernate are the classes you use as "form beans." By nature, this will lead to a more robust domain model, in part because it's going to cut down on the number of classes.
  • Spring form tags make it easier to create forms without much hassle.

In addition, Spring is HUGE - so there are a lot of other things you might be interested in using in a web app such as Spring AOP or Spring Security. But the four things listed above describe the common components of Spring that are used in a web app.

bpapa
  • 21,409
  • 25
  • 99
  • 147
9

Spring is great for gluing instances of classes together. You know that your Hibernate classes are always going to need a datasource, Spring wires them together (and has an implementation of the datasource too).

Your data access objects will always need Hibernate access, Spring wires the Hibernate classes into your DAOs for you.

Additionally, Spring basically gives you solid configurations of a bunch of libraries, and in that, gives you guidance in what libs you should use.

Spring is really a great tool. (I wasn't talking about Spring MVC, just the base framework).

bluish
  • 26,356
  • 27
  • 122
  • 180
stevedbrown
  • 8,862
  • 8
  • 43
  • 58
9

I see two parts to this:

  1. "What exactly is Spring for" -> see the accepted answer by victor hugo.
  2. "[...] Spring is [a] good framework for web development" -> people saying this are talking about Spring MVC. Spring MVC is one of the many parts of Spring, and is a web framework making use of the general features of Spring, like dependency injection. It's a pretty generic framework in that it is very configurable: you can use different db layers (Hibernate, iBatis, plain JDBC), different view layers (JSP, Velocity, Freemarker...)

Note that you can perfectly well use Spring in a web application without using Spring MVC. I would say most Java web applications do this, while using other web frameworks like Wicket, Struts, Seam, ...

Tom De Leu
  • 8,144
  • 4
  • 31
  • 30
6

The advantage is Dependency Injection (DI). It means outsourcing the task of object creation.Let me explain with an example.

public interface Lunch
{
   public void eat();
}

public class Buffet implements Lunch
{
   public void eat()
   {
      // Eat as much as you can 
   }
}

public class Plated implements Lunch
{
   public void eat()
   {
      // Eat a limited portion
   }
}

Now in my code I have a class LunchDecide as follows:

public class LunchDecide {
    private Lunch todaysLunch;
    public LunchDecide(){
        this.todaysLunch = new Buffet(); // choose Buffet -> eat as much as you want
        //this.todaysLunch = new Plated(); // choose Plated -> eat a limited portion 
    }
}

In the above class, depending on our mood, we pick Buffet() or Plated(). However this system is tightly coupled. Every time we need a different type of Object, we need to change the code. In this case, commenting out a line ! Imagine there are 50 different classes used by 50 different people. It would be a hell of a mess. In this case, we need to Decouple the system. Let's rewrite the LunchDecide class.

public class LunchDecide {
    private Lunch todaysLunch;
    public LunchDecide(Lunch todaysLunch){
        this.todaysLunch = todaysLunch
        }
    }

Notice that instead of creating an object using new keyword we passed the reference to an object of Lunch Type as a parameter to our constructor. Here, object creation is outsourced. This code can be wired either using Xml config file (legacy) or Java Annotations (modern). Either way, the decision on which Type of object would be created would be done there during runtime. An object would be injected by Xml into our code - Our Code is dependent on Xml for that job. Hence, Dependency Injection (DI). DI not only helps in making our system loosely coupled, it simplifies writing of Unit tests since it allows dependencies to be mocked. Last but not the least, DI streamlines Aspect Oriented Programming (AOP) which leads to further decoupling and increase of modularity. Also note that above DI is Constructor Injection. DI can be done by Setter Injection as well - same plain old setter method from encapsulation.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
Sumit Pokhrel
  • 2,087
  • 24
  • 18
  • But even in case of Spring, we still would be defining beans. and the bean id will be given in the code, isn't it ? so if you change the bean tomorrow, you still have to change the code, isn't it ? so what's the benefit. – Arpan Buch Aug 22 '18 at 03:47
  • 1
    @ArpanBuch I think the benefit of spring is that you can choose a different implementation without recompiling any code (so long as the other implementation already exists). I'm a beginner, so I could be wrong. – byxor Sep 16 '19 at 13:14
5

The accepted answer doesn't involve the annotations usage since Spring introduced support for various annotations for configuration.

Spring annotations approach (Dependency Injection)

There the another way to wire the classes up alongside using a XML file: the annotations. Let's use the example from the accepted answer and register the bean directly on the class using one of the annotations @Component, @Service, @Repository or @Configuration:

@Component
public class UserListerDB implements UserLister {
    public List<User> getUsers() {
        // DB access code here
    }
}

This way when the view is created it magically will have a UserLister ready to work.

The above statement is valid with a little bonus of no need of any XML file usage and wiring with another annotation @Autowired that finds a relevant implementation and inject it in.

@Autowired
private UserLister userLister;

Use the @Bean annotation on a method used to get the bean implementation to inject.

Nikolas Charalambidis
  • 40,893
  • 16
  • 117
  • 183
  • Wrong. You cannot use the `@Bean` annotation on class level. Must be one of `@Component`, `@Service`, `@Repository` etc. Rest is correct. You should maybe also point out that Autowiring the Interface in this way will only work if there is only 1 candidate class in classpath suitable for injection, otherwise Spring application error. – Stefano L Mar 02 '18 at 09:53
  • @StefanoL: Yes, you are right. I wonder people ignored my mistake. Thanks for the comment. – Nikolas Charalambidis Mar 02 '18 at 19:04
4
  • Spring is a lightweight and flexible framework compare to J2EE.
  • Spring container act as a inversion of control.
  • Spring uses AOP i.e. proxies and Singleton, Factory and Template Method Design patterns.
  • Tiered architectures: Separation of concerns and Reusable layers and Easy maintenance.

enter image description here

Premraj
  • 72,055
  • 26
  • 237
  • 180
  • 1
    ```Spring Framework help you with several things like, don't reinvent the wheel. you can connect very easily with some database just using Spring Data, or create schedule tasks like CronJob or Windows Task. amazing !``` – tomj0101 Dec 05 '17 at 06:21
3

Spring is a good alternative to Enterprise JavaBeans (EJB) technology. It also has web framework and web services framework component.

fastcodejava
  • 39,895
  • 28
  • 133
  • 186
  • 1
    Can I correct? *Was* alternative to (horrible) EJB 2 ... seems "new EJB" (in part, JPA 2, etc) has grooving acceptance. "Happy hours" of spring part "a kind of EJB" seems be past. a.d. 2015 – Jacek Cz Sep 20 '15 at 09:30
1

Spring started off as a fairly simple dependency injection system. Now it is huge and has everything in it (except for the proverbial kitchen sink).

But fear not, it is quite modular so you can use just the pieces you want.

To see where it all began try:

http://www.amazon.com/Expert-One-Design-Development-Programmer/dp/0764543857/ref=sr_1_1?ie=UTF8&s=books&qid=1246374863&sr=1-1

It might be old but it is an excellent book.

For another good book this time exclusively devoted to Spring see:

http://www.amazon.com/Professional-Java-Development-Spring-Framework/dp/0764574833/ref=sr_1_2?ie=UTF8&s=books&qid=1246374863&sr=1-2

It also references older versions of Spring but is definitely worth looking at.

Pablojim
  • 8,542
  • 8
  • 45
  • 69
1

Spring was dependency injection in the begining, then add king of wrappers for almost everything (wrapper over JPA implementations etc).

Long story ... most parts of Spring preffer XML solutions (XML scripting engine ... brrrr), so for DI I use Guice

Good library, but with growing depnedenciec, for example Spring JDBC (maybe one Java jdbc solution with real names parameters) take from maven 4-5 next.

Using Spring MVC (part of "big spring") for web development ... it is "request based" framework, there is holy war "request vs component" ... up to You

Azzabi Haythem
  • 2,318
  • 7
  • 26
  • 32
Jacek Cz
  • 1,872
  • 1
  • 15
  • 22
  • 1
    I believe now Spring framework is trying to move away from XML to Annotations and Java configuration. – Maksim Sep 21 '15 at 01:44
0

Spring framework is definitely good for web development and to be more specific for restful api services.

It is good for the above because of its dependency injection and integration with other modules like spring security, spring aop, mvc framework, microservices

With in any application, security is most probably a requirement.
If you aim to build a product that needs long maintenance, then you will need the utilize the Aop concept.

If your application has to much traffic thus increasing the load, you need to use the microservices concept.

Spring is giving all these features in one platform. Support with many modules.
Most importantly, spring is open source and an extensible framework,have a hook everywhere to integrate custom code in life cycle.

Spring Data is one project which provides integration with your project.


So spring can fit into almost every requirement.

thechaoticpanda
  • 396
  • 2
  • 18
pratik deshai
  • 2,770
  • 2
  • 11
  • 13
0

In the past I thought about Spring framework from purely technical standpoint.

Given some experience of team work and developing enterprise Webapps - I would say that Spring is for faster development of applications (web applications) by decoupling its individual elements (beans). Faster development makes it so popular. Spring allows shifting responsibility of building (wiring up) the application onto the Spring framework. The Spring framework's dependency injection is responsible for connecting/ wiring up individual beans into a working application.

This way developers can be focused more on development of individual components (beans) as soon as interfaces between beans are defined.

Testing of such application is easy - the primary focus is given to individual beans. They can be easily decoupled and mocked, so unit-testing is fast and efficient.

Spring framework defines multiple specialized beans such as @Controller (@Restcontroller), @Repository, @Component to serve web purposes. Spring together with Maven provide a structure that is intuitive to developers. Team work is easy and fast as there is individual elements are kept apart and can be reused.

Witold Kaczurba
  • 9,845
  • 3
  • 58
  • 67