close

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
ArticlesSpring framework

Spring Series Tutorial

Spring is an open source framework created to address the complexity of enterprise application development.

Start to build lightweight, robust J2EE applications using Spring technology with the following Spring series articles. The Spring series articles was rated as the best article and has the highest visits and ratings of all time , in last 10 years (2000-2010) of IBM devloperWorks. Thanks to all the readers. I will be updating the Spring series with the latest release, for now enjoy the articles.

To get started on Spring 2 framework, View my book Beginning Spring Framework 2

read more
ArticlesMQSeriesSpring framework

Spring Series Tutorial – Spring JMS

In this fourth and final installment of the Spring Series , I introduce you to features of the Spring JMS (Java Message Service) framework. JMS defines a standard way for Java applications to create and exchange messages through a Message Oriented Middleware (MOM).

As in the previous articles of this series, I use a simple example to demonstrate the features of Spring JMS. You’ll follow along as I develop a point to point (P2P) message-based system, using the Spring JMS framework to integrate with IBM’s WebSphere MQ through a JMS Interface. Upon completing the exercise, you’ll be able to send and receive simple text messages through the system.

Download the article source before you begin. The examples was tested on IBM WebSphere MQ 5.3. You will also need Apache Ant to run the example application.

Spring JMS

Spring’s JMS abstraction framework simplifies the use of JMS APIs and smoothly integrates with JMS providers such as IBM’s WebSphere MQ 5.3. The package org.springframework.jms.core provides the core functionality for using JMS in Spring. Its template classes simplify the use of the JMS by handling the creation and release of resources.

Like most other Spring template classes, the JMS template classes provide helper methods that perform common operations. In cases that require more sophisticated usage, the classes delegate the essence of the processing task to user-implemented callback interfaces. The JMS classes offer convenience methods for sending a message, consuming a message synchronously, and exposing a JMS session and message producer to the user. (more…)

read more
ArticlesSpring framework

Spring Series Tutorial – Swing into Spring MVC

In this third installment of the Spring Series, I introduce you to the Spring Model-View-Controller (MVC) framework. As in the previous articles, I use a banking example to show you how to model and build a simple application. The example application will encompass some of the techniques you’ve already learned — such as dependency injection — but will primarily demonstrate features of Spring MVC.

Download the article source before you begin.

The Spring MVC framework

The Spring framework provides a full-featured MVC module for building Web applications. With Spring’s pluggable MVC architecture, you can choose whether you want to use the built-in Spring Web framework or a Web framework such as Struts. The framework is highly configurable through strategy interfaces and accommodates multiple view technologies such as JavaServer Pages (JSP) technology, Velocity, Tiles, iText, and POI. The Spring MVC framework is view agnostic, so does not push you to use only JSP technology. Spring MVC separates the roles of the controller, the model object, the dispatcher, and the handler object, which makes them easier to customize.

Spring’s Web MVC framework is designed around a DispatcherServlet that dispatches requests to handlers, with configurable handler mappings, view resolution, locale, and theme resolution as well as support for upload files. The default handler is a very simple Controller interface with just one method, ModelAndView handleRequest(request, response). Spring provides a controller hierarchy that can be subclassed. If your application needs to process user entry forms you might subclass AbstractFormController. If you need to process a multi-page entry into a single form you can subclass AbstractWizardFormController. (more…)

read more
ArticlesSpring framework

Spring Series Tutorial – When Hibernate meets Spring

In the previous installment of this series, I introduced the seven modules of the Spring framework, including Spring AOP and the inversion of control (IOC) container. I then used a simple example to show you how the IOC pattern (as implemented by the Spring IOC container) works to integrate disparate systems in a loosely coupled manner.

Now, I pick up where I left off and, with an example similar to the one you encountered last time, demonstrate Spring’s persistence support. Because this banking example incorporates the declarative transaction handling of Spring AOP and the persistence backbone of Spring Hibernate, I’ll start with a closer look at each of these technologies.

Download the article source.

Spring AOP

Software systems are typically composed of several components, each responsible for a specific area of functionality. Often, however, these components carry additional responsibility beyond their core functionality. System services such as logging, transaction management, and security frequently find their way into components whose core responsibility is something else. The result is sometimes known as code tangling, or more simply, “a mess.” Aspect-oriented programming is a programming technique that seeks to resolve this problem by promoting separation of concerns as a core programming concept.

With AOP, you still define a system’s common functionality in one place, but you can declaratively define how and where to apply this functionality. If you modularize crosscutting concerns, such as logging and transaction management, it becomes possible to add new features to your code without modifying each class individually. Such modularized concerns are known as aspects.

Did you know?

You can use Spring framework functionality in any Javaâ„¢ Enterprise Edition (JEE) server. Also, you can adapt most of it to non-managed environments. A central focus of Spring is to allow for reusable business and data-access objects that are not tied to specific JEE services. You can reuse such objects across JEE environments (Web or Enterprise JavaBeans(EJB)), standalone applications, test environments, and so on, without any hassle. (more…)

read more
1 2
Page 1 of 2