D
D
Daniel2018-03-12 05:40:19
Java
Daniel, 2018-03-12 05:40:19

What gives Java Spring?

I would like to learn a framework in java, I started reading a textbook on spring, and I already lost count of the list of different technologies that you need to know before mastering it, and yet I still don’t understand what is the benefit of Spring?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Eugene, 2018-03-12
@zolt85

The Spring Framework, like any other self-respecting framework, gives you a framework, a skeleton, a coordinate system in which you (and more importantly, not only you, but also other developers) understand and navigate. And using this skeleton, you can build applications. At its core, the Spring Framework is about beans, bean management, and IoC (Inversion of Control). On top of all this, the rest of the Spring Security, Spring MVC and other modules are built (thousands of them!).

A
Alexey Cheremisin, 2018-03-12
@leahch

The whole idea of ​​spring and others like it is in DI and IoC technologies. The first DI
technology is Dependency Injection - dependency injection. The meaning is the following, let's say we have a class that depends on another class, then the container will automatically find all the dependencies and initialize the required class itself. Example: let's say we have an interface "Fruit", a class "Apple", an interface "Parasite", a class "Worm". In the "Apple" class, we specify in one of the methods or the constructor the dependence on the "Parasite" interface. Now let's put the "Worm" and "Apple" classes in the container, and ask the container to create to give us an instance of the "Apple" class. The container will do the following: - look that without a class,
- look at the registered classes to see if anyone implements the "Parasite" interface and detect the "Worm" class
- create an instance of the "Worm" class
- create an instance of the "Apple" class and pass the instance of the "Worm" class to it
- give the created "Apple" instance to us .
Now we can create the "Eve" class with a dependency on the "Fruit" interface, put it in a container, and put the "Adam" class with a dependency on "Eve" in the container and ask us to create an instance of the "Adam" class :-)

MutablePicoContainer pico = new DefaultPicoContainer();
pico.addComponent(Fruit.class);
pico.addComponent(Worm.class);
pico.addComponent(Eve.class);
pico.addComponent(Adam.class);
.....
Adam adam = pico.getComponent(Adam.class);

The second IoC technology - Inversion of Control - is just one of the implementations of the DI principle, when dependency injection occurs through an intermediary - a framework.
The easiest way to figure this out (and only then move on to spring) is to work with simple containers like picocontainer , nanocontainer and guice.
- picocontainer.com/introduction.html
- https://github.com/google/guice

S
Sergey Nizhny Novgorod, 2018-03-12
@Terras

Hi
Read the book Spring for Professionals 4 - you will understand what spring is for and what it gives you in general. If you just need to make some kind of website or web project in one hand or with a small team, then immediately forget it and run from Spring - this is clearly not your choice.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question