Notizen
Ohne Titel
Inhalt der Notizen (1)
Seite 1
SPRING
can create objects
can manage objects
Inversion of control - Spring is creating object for us.. we just need to change the spring.xml
Dependency injection - 2 types:
1. Setter injection --> <Property> tag
2. Constructor injection --> <constructor-arg>
Spring framework is lightweight because of its POJO implementation. The Spring Framework doesn't force the programmer to inherit any class or implement any interface. That is why it is said non-invasive.
The main tasks performed by IoC container are:
to instantiate the application class
to configure the object
to assemble the dependencies between the objects
There are two types of IoC containers. They are:
1. BeanFactory
2. ApplicationContext
It is better to use ApplicationContext than BeanFactory. It adds some extra functionality than BeanFactory such as simple integration with Spring's AOP, message resource handling (for I18N), event propagation, application layer specific context (e.g. WebApplicationContext) for web application.
The Dependency Lookup is an approach where we get the resource after demand.
The Dependency Injection is a design pattern that removes the dependency of the programs. In such case we provide the information from the external source such as XML file.
Spring framework provides two ways to inject dependency
1. By Constructor <constructor-arg>
2. By Setter method
By Constructor <constructor-arg>
<bean id="e" class="com.javatpoint.Employee">
<constructor-arg value="10" type="int"></constructor-arg>
</bean>
will call the constructor with one parameter which is of int type
<constructor-arg value="Sonoo"></constructor-arg>
will call the constructor with one parameter which is of String type
<bean id="e" class="com.javatpoint.Employee">
<constructor-arg value="10" type="int" ></constructor-arg>
<constructor-arg value="Sonoo"></constructor-arg>
</bean>
will call the constructor with two parameters - int and String
<constructor-arg> <ref bean="a1"/> </constructor-arg>
Refering to another bean which is defined in spring.xml with id 'a1'. This is Dependency Injection.
Informationen
- Beschreibung
- Notiz am Ohne Titel, erstellt von Kapil Vyas am 06/12/2019.
- Erstellt von
- Kapil Vyas
- Aufrufe
- 0
- Bewertung