Many times I meet developers who come from other platforms and want to learn Java due to the wide possibilities that the job market has. Sooner rather than later they are in dire need of learning the Spring Framework. However, many of the concepts that Spring provides are not elementary concepts and it is difficult to clarify the ideas and make a composition of the place. What exactly is Spring Framework?.
The universe of Frameworks
Normally when we work on any platform we usually use some kind of framework. These frameworks are neither more nor less than a set of classes that greatly facilitate our daily work. We use the framework to create a set of objects that our application needs.
In most cases, to develop the application we need, it is not enough to use a single framework but we need to use several frameworks. Each of which will generate its own set of objects.
This situation generates problems since each framework is totally independent and manages its own life cycle of the objects.
Spring helps to solve this problem since it changes the responsibilities and instead of the developer himself being in charge of generating the objects of each of the frameworks, it is Spring based on xml files or annotations, the one in charge of building all the objects that the application will use.
In this way, since Spring is in charge of initializing all the objects of the different frameworks, it is also responsible for ensuring that they are integrated in the correct way.
Spring and Code
So it is very common to find Spring framework applications with large XML files that are responsible for initializing the different objects as shown below.
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="ServicioA" class="com.genbetadev.ServicioA"> <property name="mensaje" value="Hola GenBetaDev"/> </bean> <bean id="ServicioB" class="com.genbetadev.ServicioB"> <property name="mensaje" value="Hola GenBetaDev 2"/> </bean> </beans>
Remember that they can also be configured through annotations with @Autowired using the principle of the Configuration Convention. This would significantly reduce the size of the XML file.
In GenBetaDev | Introduction to Spring Framework