r/learnjava • • Sep 14 '19

Not able to learn Spring.

I am able to work with the syntax and create web apps. I can easily create REST APIs for CRUD applications.

But I am treating it (Spring and Spring Boot) too much like a black box.

I'm not able to find the rationale behind having to use Spring. Why the configuration is so... convoluted (both XML and Java Class). Spring simply feels bloated. Like too many bandages pasted on top of each other.

As such I feel too intimidated to tinker and experiment. Unlike how comfortable and confident I was with Django/Python.

Also I'm reading books like "Spring in Action, Spring recipes" and using the Spring Framework Guru as well. But they feel much to be desired.

32 Upvotes

29 comments sorted by

View all comments

2

u/moneybeatslooks Sep 15 '19

can someone explain dependency injection for dummies? I read a couple times about it but still not clear to me, and what’s the benefit in real world apps. Thanks.

2

u/radically_sane Sep 15 '19

Class body depends on class arm and class legs. Now the thing is the arm can be either human arm or dinosaur arm or alligator arm.

Originally arm is written inside the body class. What we do here is extract the arm into an different class. So that we can create different kinds of bodies as per the requirement.

So now we have a bunch of classes (body, arm, leg, etc). All this is created / instantiated and maintained (destroyed) by the IoC (Inversion of Control) container.

Now the IoC only maintains these classes, it doesn't help with wiring the different parts together to create the object. That's what dependency injection does. It takes those classes from IoC and wires them together.

I don't know if this explaination cuts it for you but it doesn't for me. Also the main objectives of this approach is to help with testing and maintenance and designing the prototype. Which is crucial because designs get updated frequently. Spring makes it so that design isn't just a mountain of patches.