Class Notes
Class Notes
Depends-On
----------
class Car {
class Robot {
}
-------------------------------------------------------------
<bean id="c" class="pkg.Chip" />
Bean Aliasing
=============
If you want write a bean name including comma or space then we should use alias
tag.
------------------------------------------------------------------
Amazon - E-Commerce
BlueDart
To perform initialization and destruction operations for a Bean we can use bean
life cycle.
- IntializingBean- afterPropertiesSet()
- DisposableBean- destroy()
3) Annotation approach
<bean id="e1" class="pkg.Engine" />
------------------------------------------------
p2
p3
p4
p5,
Bean Aliasing
-------------
id vs name
ApplicationContext
------------------
If IOC is injected to our target class, then target class can decide which
dependent object it should load in runtime based on conditions.
BeanFactoryAware
----------------
//logic
}
Factory Methods
---------------
The method which is responsible to creat same or different class object is called
as factory method.
Calendar c = Calendar.getInstance();
class Car {
-------------------------------------------
Calendar c = Calendar.getInstance( ) ;
12-May-2019 + 57 = ?
new Date()
SimpleDateFormat
----------------
Date parse(String str) -----> String to Date conversion
----------------------------------
I 18 N
Property Editors
Event Handling
web components
service components
persistent components
Method Injections
-----------------
1) LookUp method Injection : When we want to inject prototype bean into singleton
bean
tg.getToken(); // 1234
tg.getToken( ); //1234
<bean id="t" class="com.airtel.beans.Token" scope="prototype" />
Car c1 = ctxt.getBean("c",Car.class);
sysout(c1.getClass().getName()); //pkg.Car
In this situation our project classes are tightly coupled with spring framework
dependencies.
-> To execute post initialization and pre-destruction logic we can write in user
defined methods.
Bean Post Processor will execute after bean instantiation and before bean
initialization.
Note 1: ApplicationContext can recognize BeanPostProcessor automatically and will
register those.
3) Annotation approach
------------------------
BeanPostProcessor
------------------
This is used to execute some common logic for all beans before initialization and
after initialization.
BeanFactoryPostProcessor
------------------------
This is used to modify ioc container metadata.
FactoryPostProcessor will execute after beans are loaded and before instantiation
of beans.
one is PropertyPlaceholderConfigurer
BeanFactoryPostProcessor :- After Beans are loaded and before Instantiation BFP
will execute.
PropertyPlaceholderConfigurer
US - country code
EN - language code
Property Editors
----------------
Integer id;
String name;
Double ticketPrice;
//setter methods
}
<bean id="m" class="pkg.Movie">
<property name="id" value="101"/>-- setId(101);
<property name="name" value="Titanic"/> -- setName("Titanic")
<property name="ticketPrice" value="350.00"/>
--setTicketPrice(350.00);
</bean>
PropertyEditors
-----------------
languageCode_CountryCode
hi_IN
-----------------------------------------------------------------
Resource Bundles
key=value
------baseName.properties----------------
key=value
--------baseName_langCd_CountryCode.properties----------
---------------------------------------------------------------
ctxt.getMessage(key,new Object[]{"Raju"},Locale.GERMANY);
Property Editors
----------------
setNums(10,20) ; //in-valid
----------------------------------------------------------------------