Introduction of Spring
- Spring framework is developed to simplify the developed of enterprise application in Java technologies. It is an open source frame work begin developed by Spring source Company. Spring framework is also available for .NET framework (Spring .NET).
- The Spring is light weight, non-invasive IoC Container and AOP framework. It provides support for JPA, Hibernate, Web services, Schedulers, Ajax, Struts, JSF and many other frameworks. The Spring MVC components can be used to developed MVC based web applications. Spring framework provides many features that makes the development of enterprise application easy work.
What is Spring?
Spring is an open source framework created to address the complexity of enterprise application development. One of the chief advantages of the Spring framework is its layered architecture, which allows you to be selective about which of its components you use while also providing a cohesive framework for J2EE application development.
Advantages of Spring framework
- Spring has layered architecture. Use what you need and leave you don't need now.
- Spring Enables POJO Programming. There is no behind the scene magic here. POJO programming enables continuous integration and testability.
- Dependency Injection and Inversion of Control Simplifies JDBC
- Open source and no vendor lock-in.
Features of Spring
- Loose Coupling
- Aspect Oriented
- MVC Framework
- Transaction Management
- JDBC Exception handling
Spring Tags
configuration and uses:--
1) How
Load properties in your project:-
a) <util:properties
id="yourProperties" location:="file:${YOUR_ENV_VAR_NAME}"/>
b)
<context:property-placeholder
location="file:${YOUR_ENV_VAR_NAME}"/>
2) How
registered stereotyped with spring:-
We can registered
stereotyped with spring by using <context:component-scan/>.
It's auto-include
AutoWiredAnnotationBeanPostProcessor &
CommonAnnotaitonBeanPostProcessor, while <context:annotation-config/>
omitted it.
3) How
registered spring annotation configuration: -
We can registred it by
using the <context:annotation-config/>
element. It's used to auto-register all
spring substandard PostProcessor for annotation based configuration.
In this element we have to define the
org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping
&
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.
4) How
auto-registered annotation handler mapping and adapter:-
We can use it
<mvc-annotation-config/> element.
It's used to auto-registered DefaultAnnotationHandlerMapping &
AnnotationMethodHandlerAdapter beans. Then we have no need to use
<context:annotation-config/> element and no need to define the
DefaultAnnotationHandlerMapping & AnnotationMethodHandlerAdapter
beans in configuration meta file.
5) How
registered a default static page with spring configuration file:-
We can use it
<mvc:view-controller/>
element to setup the explict mapping to the static page.
6)
How use jndi in Spring:-
We can use it by using
the <jee:jndi-lookup/>
element. This element has number for attributes like:- id, jndi-name,
resource-ref, default-ref.
Example :-
<jee:jndi-lookup id="datasource" jndi-name="jsd_jndi"
resource-ref="true" default-ref="devDataSource"/>
7) How
enable AOP in Spring:-
We can do it by using the
<aop:aspectj-autoproxy/>
element. This element contains two attributes
proxy-target-class={"true/false"}
& expose-proxy={"true/false"}.
And
we have to use @Aspectj annotation on AOP bean & define this bean
in spring configuration file. expose-proxy
is used when we used the @Around aop in project before using it we
have to set true, by default it's false.
Or we can use the
@Component or @Controller annotation on bean. For auto-registered
with bean during the <context:component-scan/>.
Let's start with Spring MVC feature:-
Model View Controller (MVC) is design pattern. It's behave like a front controller. In which, all requests are handled by a main controller. In Spring MVC, that controller is Dispatcher Servlet. Which handled all request. It's more power full controller, from other web mvc controller. Dispatcher Servlet is completely integrated with Spring IOC. By using IOC we can use other advance feature of Spring Framework.
MVC for Java Web Application
Model :- Java POJO
View :- JSP
Controller : - Servlet
Spring’s MVC Approach
Model :- Java Map
View :- Pluggable view technology (jsp, tiles, velocity etc.)
Controller : - Spring Controller Classes
Note:- You cannot add advice to final methods when you use Spring MVC. For example, you cannot add
advice to the AbstractController.setSynchronizeOnSession() method. Refer to
the section called “Understanding AOP proxies” for more information on AOP proxies and why
you cannot add advice to final methods.
1. Spring Web Flow:-
flow. SWF integrates with existing frameworks like Spring MVC, Struts, and JSF, in both servlet and
portlet environments. If you have a business process (or processes) that would benefit from a
conversational model as opposed to a purely request model, then SWF may be the solution.
SWF allows you to capture logical page flows as self-contained modules that are reusable in
different situations, and as such is ideal for building web application modules that guide the user
through controlled navigations that drive business processes.
For more information about SWF, consult the Spring Web Flow website.
2. Powerful and straightforward configuration of both framework and application classes as JavaBeans.
3. Adaptability, non-intrusiveness, and flexibility. Define any controller method signature you need,
possibly using one of the parameter annotations (such as @RequestParam, @RequestHeader,
@PathVariable, and more) for a given scenario.
4. Reusable business code, no need for duplication
5. Customizable binding and validation
6. Customizable handler mapping and view resolution
7. Flexible model transfer. Model transfer with a name/value Map supports easy integration with any
view technology.
8. Customizable locale and theme resolution, support for JSPs with or without Spring tag library, support
for JSTL, support for Velocity without the need for extra bridges, and so on.
9.Beans whose lifecycle is scoped to the current HTTP request or HTTP Session. This is not a specific
feature of Spring MVC itself, but rather of the WebApplicationContext container(s) that Spring
MVC uses
Implementation of Spring MVC:-
We can implement Spring MVC in two way:-
1. By extending the controller classes, like org.springframework.web.servlet.mvc.AbstractController
2. Or by using annotation tag, like @Controller ( org.springframework.stereotype.Controller)
Let's start with Spring MVC feature:-
Model View Controller (MVC) is design pattern. It's behave like a front controller. In which, all requests are handled by a main controller. In Spring MVC, that controller is Dispatcher Servlet. Which handled all request. It's more power full controller, from other web mvc controller. Dispatcher Servlet is completely integrated with Spring IOC. By using IOC we can use other advance feature of Spring Framework.
This pattern helps to develop flexible & loosely coupled web applications. And it is helped to separate the business logic, presentation logic and navigation logic.
MVC for Java Web Application
Model :- Java POJO
View :- JSP
Controller : - Servlet
Spring’s MVC Approach
Model :- Java Map
View :- Pluggable view technology (jsp, tiles, velocity etc.)
Controller : - Spring Controller Classes
Note:- You cannot add advice to final methods when you use Spring MVC. For example, you cannot add
advice to the AbstractController.setSynchronizeOnSession() method. Refer to
the section called “Understanding AOP proxies” for more information on AOP proxies and why
you cannot add advice to final methods.
1. Spring Web Flow:-
Spring Web Flow (SWF) aims to be the best solution for the management of web application page
flow. SWF integrates with existing frameworks like Spring MVC, Struts, and JSF, in both servlet and
portlet environments. If you have a business process (or processes) that would benefit from a
conversational model as opposed to a purely request model, then SWF may be the solution.
SWF allows you to capture logical page flows as self-contained modules that are reusable in
different situations, and as such is ideal for building web application modules that guide the user
through controlled navigations that drive business processes.
For more information about SWF, consult the Spring Web Flow website.
2. Powerful and straightforward configuration of both framework and application classes as JavaBeans.
3. Adaptability, non-intrusiveness, and flexibility. Define any controller method signature you need,
possibly using one of the parameter annotations (such as @RequestParam, @RequestHeader,
@PathVariable, and more) for a given scenario.
4. Reusable business code, no need for duplication
5. Customizable binding and validation
6. Customizable handler mapping and view resolution
7. Flexible model transfer. Model transfer with a name/value Map supports easy integration with any
view technology.
8. Customizable locale and theme resolution, support for JSPs with or without Spring tag library, support
for JSTL, support for Velocity without the need for extra bridges, and so on.
9.Beans whose lifecycle is scoped to the current HTTP request or HTTP Session. This is not a specific
feature of Spring MVC itself, but rather of the WebApplicationContext container(s) that Spring
MVC uses
Implementation of Spring MVC:-
We can implement Spring MVC in two way:-
1. By extending the controller classes, like org.springframework.web.servlet.mvc.AbstractController
2. Or by using annotation tag, like @Controller ( org.springframework.stereotype.Controller)
No comments:
Post a Comment