I’m working with Spring now. Before that I asked @Voodoo and some others a same question but on congdongjava.com.
If you need i will give you what i received. You just only need manage 3 things and all after that maybe easy for you
- Java bean - here is a my post about java bean
- Spring DI
- IOC
In fact, the core of Spring is IoC (Inversion of Control) and DI
(dependency injection). So if you know clearly OOP and the
characteristics of interface, it is easy for studying Spring - according
to my experience .
on the side of ebook, i want to recommend you “Spring in pratice” - a good book for Spring.
with Spring Framework, we can imagine so that:
-
in the normal, when we want have an instance, we must to initialize
an object by calling the keyword “new”, right ? and we want to use this
instance anywhere in the application ? what should we do ? we create a
global variable, right ? so we must to manage it (create, call, destroy)
-
and now, instead of us who manage the objects like that, Spring will
do it. All you need to do is declare the object that you want. Enough
!!!
For ex: No Spring and with Spring
*No Spring:
-
i have class DBConnection - responsible for creating connection and manipulating with DB
-
i want to insert a Customer, i have to new DBConnection, right ? and call function executeQuery(String sql), right ?
-
now, i want to insert a Product, i have to new DBConnection and call function executeQuery(String sql), not news
-
i will do that for actions CRUD. it’s so tedious when we have to initialize this object in many time of use
*With Spring:
-
i have to declare object DBConnection with id=“dbConnect”,
-
if i want to insert a Customer, i will tell with Spring: “hey
brother, give instance with id = dbConnect”. Spring will find and
respond to your demand: " here, take it and use it, just use it, without
initialize it, and don’t worry after, i will manage it". Immediately, i
have the instance of DBConnection and just call function
executeQuery(…
-
and i want to insert a Product. no news, i demand Spring “hey guy, i
want to the instance with id = dbConnect”. Like that, i have
immediately this instance and calling function. But 2 instance is the
same.
Every time i want to use this instance, i just tell to Spring and i have
it. i don’t need to manage it (init, call, destroy), Spring will do
that.
So,
when Spring init and call instance for giving me, it is IoC - inversion
of control because in the normal, instead of you who have to init it,
Spring will find that
when Spring give me the instance, it is DI - dependency injection - implemention IoC
I will have 2 posts about DI and IOC as soon as posible