Spring Overview Tuitorial
Spring Overview Tuitorial
Introduction to Spring
Motivation for Spring
Spring Background
The Spring Framework
Features of Spring framework
Spring's non-invasive programming model
Simplicity and Power
Design Principles behind Spring
Controlling Object Creation: The Core
Module
Web Applications: The Web Module
Persistence: The DAO and ORM Modules
The Aspect-Oriented Programming Module
Installation and Configuration
2
TALENTSPRINT | Copyright 2012 2
What is the Spring Framework?
Spring is a Lightweight
Application Framework
Where Struts, WebWork and
others can be considered Web
frameworks, Spring addresses all
tiers of an application
Spring provides the plumbing so
that you dont have to!
A BeanFactory is typically
configured in an XML file with the
root element: <beans>
The XML contains one or more
<bean> elements
id (or name) attribute to identify the bean
class attribute to specify the fully qualified class
package pack;
<beans>
<bean id="a" class="pack.HelloWorld">
<property name=msg> The beans fully-
qualified
<!-property value here--> classname
</property>
</bean>
</beans>
Maps to a sayHellow()
call
JDBCTemplate provides
Translation of SQLExceptions to more meaningful Spring Runtime
exceptions
Integrates thread-specific transactions
MappingSQLQuery simplifies
mapping of ResultSets to Java
objects
DispatcherServlet
35
TALENTSPRINT | Copyright 2012 35
Spring IDE - Installation
38
TALENTSPRINT | Copyright 2012 38
Select Spring features
39
TALENTSPRINT | Copyright 2012 39
First Spring project
Once the
installation is
complete you are
done. Now let's
see how to create
the hello world
example using the
Spring IDE.
First create a
Spring project, go
to File -> New ->
Project.
TALENTSPRINT | Copyright 2012 40 40
Select Spring Project and click Next
package com.company.data;
public class HelloWorld {
private String message;
public void setMessage(String message) {
this.message = message;
}
public void sayHellow()
{
System.out.println(message);
}
}
To create a new
bean
configuration file
right click the src
folder and select
New -> Spring
Bean
Configuration File.
45
TALENTSPRINT | Copyright 2012 45
Bean Configuration File
46
TALENTSPRINT | Copyright 2012 46
Bean Configuration File
47
TALENTSPRINT | Copyright 2012 47
Bean Configuration File
package com.company.apps;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;