Tuesday, January 29, 2008

Spring Framework


Spring Overview


Definition
Open source framework.
Created to address the complexity of enterprise application.
Lightweight.
Loosely coupled using inversion of control (IOC) .
Managing cross-cutting concerns with aspectoriented programming (AOP).



Why Spring?

If you are reading this book, you probably want to know why Spring would be
good for you. After all, the Java landscape is full of frameworks. What makes
Spring any different? To put it simply, Spring makes developing enterprise applications easier. We don’t expect that to convince you at face value, so first let’s take a look at life without Spring.
1.1.1 A day in the life of a J2EE developer Alex is a Java developer who has just started on his first enterprise application. Like many Java 2 Enterprise Edition (J2EE) applications, it is a web application that serves many users and accesses an enterprise database. In this case, it is a customer management application that will be used by other employees at his company. Eager to get to work, Alex fires up his favorite integrated development environment (IDE) and starts to crank out his first component, the CustomerManager component. In the EJB world, to develop this component Alex actually has to write several classes—the home interface, the local interface, and the bean itself. In addition, he has to create a deployment descriptor for this bean. Seeing that creating each of these files for every bean seems like a lot of effort, Alex incorporates XDoclet into his project. XDoclet is a code generation tool that can generate all of the necessary EJB files from a single source file. Although this adds another step to Alex’s development cycle, his coding life is now much simpler. With XDoclet now handling a lot of the grunt work for him, Alex turns his attention to his real problem—what exactly should the CustomerManager component do? He jumps in with its first method, getPreferredCustomer(). There are several business rules that define exactly what a preferred customer is, and Alex dutifully codes them into his CustomerManager bean. Wanting to confirm that his logic is correct, Alex now wants to write some tests to validate his code. But then it occurs to him: the code he is testing will be running within the EJB container. Therefore, his tests need to execute within the container as well. To easily accomplish this, he concocts a servlet that will be responsible for executing these tests. Since all J2EE containers support servlets, this will allow him to execute his tests in the same container as his EJB. Problem solved!