Spring framework

Spring framework

Spring IOC Tutorial

In my previous blog, I provided an architecture overview of the Spring framework. In this blog, I will follow it up with a simple example of using IOC using Spring. The complete source code for the application is available for download here. However, in this blog we would build the code from scratch.

I’ll take the use case of online credit card enrollment that we have discussed earlier in Part 1. With respect to the implementation, the credit card enrollment requires that the user interact with the following services:

  • A credit rating service that queries the user’s credit history information
  • A remote credit linking service that inserts and links customer information with credit card and bank information for the purpose of automatic debits (if required)
  • An e-mail service that e-mails the user about the status of his credit card

Three interfaces

For this example, I assume that the services already exist and that it is desirable to integrate them in a loosely coupled manner. The listing 1 below show the application interfaces for the three services.
Listing 1. CreditRatingInterface

public interface CreditRatingInterface {
public boolean getUserCreditHistoryInformation(ICustomer iCustomer);


The credit rating interface shown in Listing 1 provides credit history information. It requires a Customer object containing customer information. The implementation is provided by the CreditRating class.
Listing 2. CreditLinkingInterface

public interface CreditLinkingInterface {

public String getUrl();

public void setUrl(String url);

public void linkCreditBankAccount() throws Exception ;


The credit linking interface links credit history information with bank information (if required), and inserts credit card information for the user. The credit linking interface is a remote service whose lookup is made through the getUrl() method. The URL is set by the Spring framework’s beans configuration mechanism, which I discuss later. The implementation is provided by the CreditLinking class. (more…)

read more
FeaturedSpring framework

Introduction to Spring Framework

Spring is an open source framework created to simplify the complexity of enterprise application development. Spring framework addresses all tier of application development in a consistent manner. Spring framework provides a layered architecture comprising of well defined modules, where each modules can be used independently to simplify some area of enterprise development.

In this first article of the Spring Series , I introduce you to the Spring framework. I start by describing the functionality of the framework in terms of its underlying modules and then discuss two of the most interesting modules, Spring aspect-oriented programming (AOP), and the Inversion of Control (IOC) container. I then use several examples to demonstrate the workings of the IOC container in a typical application use case scenario. The examples will also lay the foundation for an expanded discussion, later in this series, of the how the Spring framework implements AOP constructs through Spring AOP.

Spring framework is a lightweight open source layered application framework created to simplify the complexity of enterprise application development. Spring has become the de facto framework for creating Java based enterprise applications.The Spring framework provides the following functionality:

  • Lightweight IoC container for lifecycle and dependency management of objects.
  • AOP functionality for modularizing cross-cutting concerns and providing services to Plain Old Java Object(POJOs) in a declarative fashion, like transaction management, logging, messaging, and exposing POJO using one of the remote technologies like RMI, HTTP , web services, and so on.
  • Consistent abstraction layer, which provides integration with various standards like JPA (Java Persistence API), JDBC, JMS, and third party APIs like Hibernate, Top Link, JDO.
  • MVC framework, which provides a highly configurable Model View Controller implementation via strategy interfaces and accommodates numerous view technologies including JSP, Portlets, Velocity, Tiles, iText, and POI.implementation.

spring30-framework (more…)

read more
ArticlesSpring frameworkViews & Opinions

Do you need to move from Spring to Java EE 6

I recently read an interesting post on TSS- “Moving from Spring to Java EE 6: The Age of Frameworks is Over”.  I am sure, everyone would have its perspective on the above blog and here are my views on this.

But before that, let’s step back and look and why frameworks like Spring was invented in the first place. In my view, primarily it was created as an alternative to J2EE stack, to keep it simplified, POJO centric and testable without the need for a container. Then came in support for various abstractions layers – JDBC, Transactions, ORM, JMS which can be applied POJO in a consistent manner and support for plugging in any web framework , all backed by principle of dependency injection. What it offered was a choice to programmers (and that’s very important) and didn’t restrict it usage to any specific API directly.  Using Spring, one could create modular components which could be run against a J2SE environment(derby and local transaction manager for your local test environment) and then promoted to use capabilities offered by J2EE Applications servers like JNDI, JTA and so on.

Over the years, J2EE tried to catch on, tried to create specifications and standardizations which were well adopted and tested by the framework like Spring or ORM providers like Hibernate. Specifications are good, but lot of time goes in creating specifications and it takes even lot more to get these specifications incorporated into the release of J2EE servers and stacks. (more…)

read more
ArticlesOSGISpring framework

Getting Started with OSGI and Spring DM

In this article we will look at how to create bundles using the Spring framework and then deploy them in a Felix runtime environment. You will see how the core OSGi framework dependency is removed through a simple Spring-based configuration.

In this article, you will revisit the order application developed in part 1 of the series. The application will now use Spring DM to build and package the bundles. The application client will invoke the service component to process the order and the server component will print the order ID. The article will help you understand the concept of Spring DM and its use with the Felix-based OSGi container.

System requirements

To run the examples in this article, make sure the following software is installed and set up on your machine:

After the above distribution is installed, set up the following environment variables: (by way of example set ANT_HOME=C:\apache-ant-1.7.0).

  • JAVA_HOME (for Java)
  • ANT_HOME (for Ant)

Next add the following to the PATH environment variable:

  • JAVA_HOME\bin
  • ANT_HOME\bin

Spring DM

Spring DM includes JARs or bundles that help deploy Spring applications in an OSGi environment. Spring DM-based applications can make use of services offered by the OSGi environment. These types of applications provide ease and convenience in the development of OSGi-based applications. (more…)

read more
ArticlesCXFSpring frameworkWeb Services

Comparing Spring Web Services and Apache CXF

Spring web services at a glance –

Spring web services is focused on creating contract-first document oriented web services. Spring web services, being a product of Spring, offer first class support of using Spring configurations and integrating with Spring framework.

Spring promotes contract-first development completely and provides an ability to plug-in various XML APIs (SAX, DOM, STAXM, XOM, JDOM..) to handle XML messages. Using Spring web services, you can always ensure the XML contract (xml schemas) is marshaled correctly into Java objects. Spring web services support JAXB 1 and 2, Castor, XMLBeans, JiBX, and XStream as part of its XML Marshalling support.

Spring web-service provides options to secure web services using Acegi security and provides ability to encrypt/decrypt messages and support for webservices security standards. (more…)

read more
BooksFeaturedSpring framework

Recommended Spring Books

To get started with Spring framework quickly, checkout this Spring Series tutorial . The series would be shortly updated with latest Spring version.

In my view, the following books are best resources to get started on Spring. This includes my book on Spring 🙂

Beginning Spring framework provides readers to get started with Spring framework quickly. In this book we don’t assume the user is aware of any J2EE Concepts and try to cover Spring 2 using a tutorial format.

Spring Recipes is a excellent book providing a problem solving approach using Spring framework. However for a beginner, in my view the approach of using problem solution approach might be a bit too much as he may not be aware of what problem exists in J2EE stack and how Spring overcomes these approach. If a user is aware of J2EE concepts and have some Java and J2EE experiences, than Spring Recipes is his best bet to get working on Spring. Also watch out for the Spring Recipes book update , which might hit Amazon soon.

read more
1 2
Page 1 of 2