Possible Duplicate:
Why not Spring framework?

I've read numerous articles about the Spring MVC framework, and I still can't see the benefits of using it. It looks like writing even a simple application with it requires creating a big hodgepodge of XML files and annotations and other reams of code to conform to what the framework wants, a whole bunch of moving parts to accomplish a simple single task.

Any time I look at a Spring example, I can see how I can write something with the same functionality using a simple servlet and template engine (e.g. FreeMarker, StringTemplate), in half the lines of code and little or no XML files and other artifacts. Just grab the data from the session and request, call the application domain objects if necessary, pass the results to the template engine to generate the resulting web page, done.

What am I missing? Can you describe even one example of something that is actually made simpler with Spring than using a combination of raw servlets with a template engine? Or is Spring MVC just one of those overly complicated things that people use only because their boss tells them to use it?

EDIT: A summarized concrete description would be helpful. For example, "I used Spring MVC to build an application that did XYZ, and its feature Q saved me from having to do the extra work of A and B and C which would have been necessary with raw servlets and a template engine." Simply mentioning marketing buzzwords like "dependency injection" doesn't clarify anything.

  • 1
    you might be missing the concept of MVC pattern.
    – Yusubov
    Jun 30 '12 at 19:06
  • @Yusubov You can have MVC with raw servlets. The servlets ARE the controllers. With annotations, you can use servlets just like you would use a controller.
    – stepanian
    Aug 2 '14 at 5:44
  • this question is not a duplicate of the reference. The referenced duplicate is a question about Spring FW where as this question is about Spring-MVC which is a subset of the Spring FW. It's possible for someone to use any subset of the Spring FW, but not specifically Spring-MVC and this person, despite being a user of the majority of the components of the Spring FW, might be interesed in knowing the benefits of the Spring-MVC
    – inor
    Aug 22 '17 at 7:39
  • dependency injection (you need this for unit tests)
  • easy to define request mappings makes creating a restful api possible in mins
  • custom jsp tags
  • jdbcTemplate
  • an enourmous library of useful functions (eg security, internationalization, device interceptor etc etc)

Is just a few of the practical benefits you can get off the top of my head. Its sheer size can be offputting, and the config is somewhat confusing to begin with, and still cause sme problems now and again (after two years).

Yes it promotes to model-view-controller, controllers are so much nicer to write than vanilla servlets (less verbose, more powerful).

It has a learning curve, once that has been passed you can definitely be more productive with spring, than without, imho.

  • I like Spring's JDBC library, but it is separate from MVC, as is internationalization etc. For the rest, those are theoretical benefits I've seen listed but no example of how it actually makes anything simpler.
    – Gigatron
    Jun 30 '12 at 21:53
  • it appears you have made your mind up and ignored the specific mvc examples I also included. It might be worth checking out some examples :blog.springsource.org/2009/03/08/rest-in-spring-3-mvc Jun 30 '12 at 22:12
  • My mind is not made up; I'm trying really hard to see the benefit of Spring MVC. But for every example I see, the Spring way is more complicated than servlets + template engine.
    – Gigatron
    Jun 30 '12 at 22:25
  • @Gigatron I agree. You can build a basic web app using servlets in the same amount of time as Spring or even less.
    – stepanian
    Aug 2 '14 at 5:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.