Core Spring Training: Highlights
Posted on | 10 October 2007 | 3 Comments
Tags: spring
Last week, I attended the Core Spring Training for the Spring Framework in Antwerp. Interface21 has been giving this course for 3 years now and have fine-tuned the material so that everything just falls into place for you. The instructor, Alef Arendsen, was one of the original creators of Spring, so it was good to hear it straight from the horse’s mouth. We learned the key concepts, how to use Spring with its many hooks for enterprise Java™ support, and got invaluable previews on the soon-to-be-released Spring 2.5.
BACK TO BASICS
Spring came about from the frustration of Java™ developers having to deal with the complexity of using EJB 1.x and 2.x. It is an application framework that allows developers to go back to the basics using POJOs to build Java™ enterprise applications. A Spring application is built on Spring beans which are POJOs wired together using dependency injection. Furthermore, Spring uses the concept of programming by interface to hide implementation details and to allow for easily changing of implementation details by configuration.
INFRASTRUCTURE
Spring as an application framework provides the infrastructure for enterprise Java™ applications so developers can concentrate on the business logic specific to their client. This prevents companies from reinventing the wheel and thus reduces the development time needed for developing an entire application. Spring provides support for many parts of enterprise applications by using the programming by interface principle and by providing out-of-the-box implementations for popular solutions. This means that if there is no built-in implementation for your solution, you can still use the framework and plug in your own custom implementation. Supported enterprise services include persistence (see Persistence below),
remoting including web services and JMS, transaction management, security, JMX, and web application frameworks (see Web Frameworks below).
PERSISTENCE
Spring provides support for a variety of persistence mechanisms including JDBC, Hibernate, JPA, Oracle Toplink, and iBatis, so that the choice of persistence mechanism is not linked to the application server. Using programming by interface, the persistence mechanism can be changed with minimal disturbance to the business logic.
ASPECT-ORIENTED PROGRAMMING
One of the foundation ideas behind Spring is the separation of concerns. Separation of concerns is expressed by among other things Spring’s support for Aspect-oriented programming. AOP separates cross-cutting concerns such as security and transaction management away from the main business logic. This does wonders in preventing cluttered code and tons and tons of copying. Aspects are linked to business logic classes in the configuration file, as opposed to in annotations. This allows defining the aspects in one place as opposed to in every class that uses an aspect. Referencing an aspect in annotations is almost the same as coding the aspect in the business logic in the same file. It violates separation of concerns.
REMOTING
One of the strengths of Spring is that it provides the same enterprise service support and separation of concerns on both the server and client sides. On the server side, POJOs can be exported for remoting using various protocols such as RMI, EJB, HTTP, or XML (Hessian or Burlap), while on the client side, out-of-the-box proxies are available to access the remote interfaces. Separating the business logic from remoting concerns allows it to be exported for use in different remoting protocols without changing the code of the business logic itself.
WEB SERVICES
One of the ways of remoting is by exporting a business object as a web service. Building web services with Spring decouples the design of the contract (wsdl) from the service interface and thereby helps with version management of web services by creating a layer of abstraction. Creating a web service with tools such as Axis binds the contract to the service interface and implementation (the wsdl is generated from the service interface during the development process). This means that if the service interface changes, the wsdl also changes and all clients that are using the old service breaks. Spring promotes a best practice for developing web services by separating the XML (message structure) from the service implementation so that the developer only has to write methods for marshalling/unmarshalling the XML and the business logic for the endpoint. All popular object-XML marshalling technologies are supported.
WEB FRAMEWORKS
Spring has hooks for Struts, JSF, and Spring’s own web-related frameworks Spring MVC and Spring Web Flow. Spring MVC is built with similar principles to Struts but allows easy access to Spring beans. However, Spring Web Flow is the first version of a next-generation web framework. It introduces the concept of a flow, which supports the development of multiple page forms or wizards. Spring MVC and Spring Web Flow will be combined in the next version.
TESTING
Spring’s idea of inversion of control and dependency injection allows applications to be easily configured for testing using stubs or mock objects. Mock objects are like dynamic stubs. With mock objects, you don’t have to develop and compile a stub class and worry about ways to trigger the right response using arguments. Instead, you can dynamically create a mock object in your test and tell it what to do when it receives a method call. You can tell it what to return or to immediately throw an exception without having to come up with the test data for it. In my experience, test data is one of the hardest thing to come by when testing large systems. Developers don’t want to come up with tons of test data and most of the time, neither does the business/client side. Mock objects provides an alternative when stubs are impractical. But stubs are still useful and preferred in many cases. Here is an article from Martin Fowler on the subject: Mocks Aren’t Stubs. In the end, the important thing is to write tests. Spring’s extensive dependency injection support promotes easier isolated testing which can result in better applications.
SUMMARY
Spring is an application framework that helps with all aspects of enterprise application development. I learned about the key concepts of Spring and how to use Spring as the infrastructure for an enterprise application, while hooking into all the popular Java™ techologies. To learn more about Spring, take the course or read the reference documentation. The key concepts behind Spring speak to me as a developer. I always try to create applications elegant, testable, extensible, and maintainable and Spring helps with doing just that.
Comments
3 Responses to “Core Spring Training: Highlights”
Leave a Reply
May 13th, 2008 @ 07:51
Hmmmmm,,,, Not Bad. Can U supply further more Information…
Anyway Thanks a lot!
September 9th, 2009 @ 07:08
Hello,
Can you please provide me the core spring training slides for my reference?
Thanks & Regards
Sriki
January 5th, 2010 @ 10:03
can you send me “Core Spring Training lab documentation”