0

I keep seeing the phrase Dependency Injection whenever I search for Spring Framework in Google.

In plane English , can someone please explain what exactly is Spring , and why would I want to use it ?

For example , a few days ago I've learned about Hibernate : it converts JAVA objects into records in a DB table ... it's great , reduces the amount of code and a bunch of SQL statements .

So, how exactly does Spring helps me?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
JAN
  • 21,236
  • 66
  • 181
  • 318

3 Answers3

1

Spring is a framework which supports (among other things) dependency injection. Using Spring also makes it very easy to create web applications. Spring favors convention over configuration and was originally created as an alternative to Java EE (which was overly complex, verbose, and burdensome). But Spring is more than just dependency injection. It has core support for dependency injection, transaction management, web applications, data access, messaging, aspect-oriented programming, testing, and more.

Spring helps you by making it easy to inject dependencies, which reduces tight coupling between a class and specific implementations. For web applications, Spring follows the MVC (Model View Controller) pattern, and has specific annotations (and XML-based configuration) to help you write code that follows this pattern.

I suggest reading more about dependency injection, MVC, and the Spring framework in general to know more; there's far too much information to cover in just a single answer.

Vivin Paliath
  • 94,126
  • 40
  • 223
  • 295
0

It creates loose coupling between elements due to DI. Best explanation as always by Martin Fowler

Recommended reading:

Marcin Szymczak
  • 11,199
  • 5
  • 55
  • 63
0

Plainer than "dependency injection"?

Let's ask what it is and why you'd use it. This is still the best explanation I know of.

Spring is more than dependency injection. It's a three legged stool:

  1. dependency injection
  2. aspect-oriented programming
  3. libraries for web MVC, database, messaging, remoting, and more

There are other DI engines out there, like Guice.

If you have to ask, I'd suggest that you dig into it more before deciding.

duffymo
  • 305,152
  • 44
  • 369
  • 561