Introduction To The Spring Framework
Introduction To The Spring Framework
University of Kansas January 2009 This presentation and example application are available at http://www.brucephillips.name/spring
References
Spring documentation http://www.springsource.org/documentation Spring API http://static.springframework.org/spring/docs/2.5.x/api/ index.html Introduction to the Spring Framework 2.5, by Rod Johnson (Originator of Spring) http://www.theserverside.com/tt/articles/article.tss?l=In trotoSpring25 Spring in Action, 2nd Edition, Manning Publishing, August 2007 Pro Spring 2.5, Apress Publishing, August 2008 Maven - http://maven.apache.org/ Maven - http://books.sonatype.com/mavenbook/index.html
What is Spring?
A Container
Creates objects and makes them available to your application
A Framework
Provides an infrastructure of classes that make it easier to accomplish tasks
See: http://www.springsource.org/download
Works with Java 1.4 or 1.5 or 1.6 and J2EE 1.3 and Java EE 5
See: http://static.springframework.org/spring/docs/2.5.x /reference/new-in-2.html
See: http://static.springframework.org/spring/docs/2.5.x/reference/introduction.html#introduction-overview
Example Application
Contact has a Person, collection of Email, and collection of Phone objects Can use an XML file or database as repository User interface is via the console See READ_ME file under project folder
Dependency Management
External Configuration
Configuration options
Properties files XML configuration files Annotations
XML Configuration
Specify the creation of objects Specify the dependencies between objects
Handling Change
Testing Applications
Easier to test
Use a test configuration file to create test objects and manage their dependencies
Reuse objects across tests
Test service layer objects by creating stub dependent objects See: http://static.springframework.org/spring/docs/2.5.x /reference/testing.html
Separation of Responsibilities
Put a concern (logic) that applies to many different objects in one single place
Logging, security, performance testing, transaction management
Advice
Several different ways to configure Advice objects
Implement interfaces and XML configuration Use @AspectJ annotations Integrate with AspectJ
Database Integration
Spring provides a JDBC framework that removes much of the boiler-plate code
See: http://static.springframework.org/spring/docs/2.5.x/reference/jd bc.html Configures the data source Gets the connection Creates the statement Processes the result Creates the business objects Handles exceptions Closes connection
Spring can integrate with Hibernate, Java Data Objects (JDO), Java Persistence API (JPA), iBATIS, and other Object Relational Management (ORM) technologies
Spring JDBC
Transaction Management
A transaction defines a logical unit of work that either completely succeeds or produces no result at all. A distributed transaction is simply a transaction that accesses and updates data on two or more networked resources, and therefore must be coordinated among those resources. see: http://archive.devx.com/java/free/articles/dd_jta/jta-1.asp
Email Scheduling Web services and remoting Spring Web Model View Controller (MVC) Integration with Struts 2
see: http://static.springframework.org/spring/docs/2.5.x/reference/we b-integration.html#struts and http://struts.apache.org/2.x/docs/spring-plugin.html
Spring in Action, 2nd Edition, Manning Publishing, August 2007 Pro Spring 2.5, Apress Publishing, August 2008