Spring Notes Vijay

You might also like

You are on page 1of 2

Spring is a lightweight dependency injection and aspect-oriented container and

framework.

Light Weight:
1) The bulk of the Spring Framework can be distributed in a single JAR file that
weighs in at just over 2.5 MB.
2) The processing overhead required by Spring is negligible.
3) Objects in a Spring-enabled application often have no dependencies on
Spring-specific classes.

Dependency Injection:
1) Spring promotes loose coupling through a technique known as Dependency
Injection.
2) Objects are passively given their dependencies instead of creating or looking
for dependent objects for themselves.

Aspect Oriented Programming:


1) This enables cohesive development by separating application business logic
from system services (such as auditing and transaction management).
2) Application objects do what they’re supposed to do—perform business logic—
and nothing more.
3) Application Objects are not responsible for (or even aware of) other system
concerns, such as logging or transactional support.

Container:
1) Spring acts as a container which contains and manages the lifecycle and
configuration of application objects. (how to declare , configure application
objects and how different application objects are associated together)

Frame Work:
1) Using spring it is possible to compose and configure complex components
using simple components
2) In Spring application objects are composed declaratively in xml file.

3) Spring also provides much of Infrastructure functionality ( like Transaction


Management, Persistance Framework Integration etc).

4) Application objects only handle business logic


Dependency Injection in Action:

package com.springinaction.chapter01.knight;

public class KnightOfTheRoundTable {


private String name;
private HolyGrailQuest quest;

public KnightOfTheRoundTable(String name) {


this.name = name;
quest = new HolyGrailQuest();
}

public HolyGrail embarkOnQuest()throws GrailNotFoundException {


return quest.embark();
}
}//End of KnightOfTheRoundTable Class

package com.springinaction.chapter01.knight;

public class HolyGrailQuest {


public HolyGrailQuest() {}

public HolyGrail embark() throws GrailNotFoundException {


HolyGrail grail = null;
// Look for grail

return grail;
}
}//End of HolyGrailQuest

package com.springinaction.chapter01.knight;
public interface Quest {
abstract Object embark() throws QuestFailedException;
}

package com.springinaction.chapter01.knight;

public class HolyGrailQuest implements Quest {


public HolyGrailQuest() {}
public Object embark() throws QuestFailedException {
// Do whatever it means to embark on a quest
return new HolyGrail();
}
}// end of HolyGrailQuest

You might also like