Architecture of Spring Application:
If Spring is used in all layer of enterprise application, then the spring application is as follows.
In spring application the following classes are used in each layer
- Presentation Layer: DispatcherServlet, Controller Classes, JSP’s
- Business Logic Layer: Business Object/Service Classes, Value Object Classes
- Data Access Layer: DAO Classes, Domain Object Classes
DispatcherServlet is the entry point into a spring application. For any kind of user request it always control to DispatcherServlet, It is known as front controller. DispatcherServlet uses controller classes as assistance for each service offered by the application. For each task of the application one controller class is used, these controller class are spring beans. For each task the controller calls the business method of the service layer class. Service layer classes are also spring beans running in the spring container. Depending upon the requirement of project and use case we develop the business object class or Service class. Service layer classes make use of DAO classes for database data. DAO classes are also Spring beans. Controller beans are dependent for service beans, Service beans are dependent on DAO beans, DAO beans are dependent on service beans, Service beans are depends on controller classes.
What are the dependencies in Spring application ?
In an object oriented system we have a collection of objects. One object needs to collaborates with another object to provide service to the end users. To process one business service in an enterprise application, DAO object collaborates with service objects. Service objects collaborates with controller objects. An object in need of another object service is known as dependent. An object that provides the service is known as dependency. In enterprise application the controller object has the following responsibilities.
- Capturing the user input.
- Calling the business method of the service object.
- Getting processed data and making it available to the view components (mostly JSP).
Note: Here controller object is dependent and service object is dependency
Service object has the following responsibilities:
- Receiving the request from controller object.
- Requesting DAO object to get database data.
- Processing data by applying business rules and returning processed data to the controller object.
NOTE: Here service object is dependent and DAO object is dependency.
DAO object uses any data accessing mechanism to get data from database and gives to Service object.