by Andy Piper, Rod Johnson, Chris Wall and Nick Tran
Originally published on BEA Dev2Dev September 2005
BEA WebLogic Server 9.0 is the leading implementation of Sun Microsystems' J2EE 1.4 platform. However, WebLogic Server's core value proposition is in areas not covered by the J2EE specification—enhanced management, ease-of-use, high availability, scalability, reliability, and performance. Indeed, WebLogic Server's value is not tied to any particular programming model, so it is therefore a natural fit with the new breed of non-J2EE programming models. The most exciting of these to emerge in recent years are models based on Inversion of Control (IoC)—of which the Spring Framework is the leading implementation. This article introduces features of the Spring Framework, WebLogic Server, and the integration of the two. As we shall see, the whole is greater than the sum of its parts.
In the first two sections, we give an overview of Spring and WebLogic Server and their respective features. If you are familiar with the Spring Framework, then you should skip over the first section, and if you are familiar with WebLogic Server, then you should skip over the second section. Since this article is primarily about the integration of the two technologies, we devote the rest of the article to this topic. To give it some context we first examine MedRec—a sample application shipped with WebLogic Server—both in its original J2EE form and then recast using the Spring Framework. After this we dive into some detail around specific integration points. If you are trying to develop Spring applications on top of WebLogic Server, then you will almost certainly find the level of detail helpful. If you just want an idea of what is possible, then read the titles and save the substance for later. Finally, we summarize and look at some of the future developments we are thinking about.
In this section, we briefly summarize the features of the Spring Framework.
Spring is a layered Java/J2EE application framework, based on code published in Expert One-on-One J2EE Design and Development by Rod Johnson (Wrox, 2002). Spring exists because we believe that J2EE should be easier to use and that it's possible to enable a simpler approach to J2EE development without sacrificing the power of the platform.
Spring enables agile J2EE development, and allows J2EE applications to be developed using POJOs.
At its core Spring provides an easy-to-configure, XML-driven, Inversion of Control (IoC) container. IoC is based on the so-called "Hollywood" principle—"don't call us—we'll call you." In this scheme relationships between Java objects in your application are injected by the container rather than programmed by you directly. This injection comes in two forms—constructor injection and setter injection—depending on whether the container injects information into a created Java object via its constructor or its mutator methods.
In Spring, injected properties—or references to other beans—are configured via an XML file, making configuration almost entirely trivial. This, coupled with an AOP framework that allows attributes such as transactions and security to be added non-invasively, means that developers can concentrate on creating a solution for your business problem rather than getting tied up in the complexity of J2EE development or configuration. Since the container is non-invasive you can also relax knowing that your business code is not polluted with vendor-specific (and we include Spring here) artifacts.
As we have mentioned, Spring provides a lightweight container offering centralized, automated configuration and wiring of your application objects. The container is non-invasive, capable of assembling a complex system from a set of loosely coupled components (POJOs) via IoC in a consistent and transparent fashion. The container brings agility and leverageability, and improves application testability and scalability by allowing software components to be first developed and tested in isolation, then scaled up for deployment in any environment (J2SE or J2EE). Additionally, Spring provides a number of other developer-friendly features that we enumerate below:
A common abstraction layer for transaction management, allowing for pluggable transaction managers, and making it easy to demarcate transactions without the need to deal with low-level issues. Generic strategies for JTA and a single JDBC DataSource are included. In contrast to plain JTA or EJB CMT, Spring's transaction support is not tied to J2EE environments.
A JDBC abstraction layer that offers a meaningful exception hierarchy (no more pulling vendor codes out of SQLException), simplifies error handling, and greatly reduces the amount of code you have to write. You'll never need to write another finally block to use JDBC again. The JDBC-oriented exceptions comply with Spring's generic DAO exception hierarchy.
Integration with industry-leading, object-relational mapping solutions, in terms of resource holders, DAO implementation support, and transaction strategies. First-class support with lots of IoC convenience features, addressing many typical O-R mapping integration issues. All of these comply with Spring's generic transaction and DAO exception hierarchies.
AOP functionality, fully integrated into Spring configuration management. You can AOP-enable any object managed by Spring, adding aspects such as declarative transaction management. With Spring, you can have declarative transaction management without EJB—even without JTA.
A flexible MVC Web application framework, built on core Spring functionality. This framework is highly configurable via strategy interfaces, and accommodates multiple view technologies like JSP, Velocity, Tiles, iText, and POI. Note that a Spring middle tier can easily be combined with a Web tier based on any other Web MVC framework, like Struts, WebWork, or Tapestry.
You can use all of Spring's functionality in any J2EE server, and most of it in non-managed environments too. A central focus of Spring is to allow for reusable business and data access objects that are not tied to specific J2EE services. Such objects can be reused across J2EE environments (Web or EJB), standalone applications, and test environments without any hassle.
Spring's layered architecture gives you a lot of flexibility. All its functionality builds on lower levels. So you can, for example, use the JavaBeans configuration management without using the MVC framework or AOP support. But if you use the Web MVC framework or AOP support, you'll find they build on the configuration framework, so you can apply your knowledge about it immediately.
In this section, we briefly summarize the features of BEA WebLogic Server, with an emphasis on the underlying infrastructure—rather than on programming models—that it provides.
WebLogic Server is a scalable, enterprise-ready J2EE application server. The WebLogic Server infrastructure supports the deployment of many types of distributed applications and is an ideal foundation for building any kind of application.
The WebLogic Server implementation of the Sun Microsystems J2EE 1.4 specification provides a standard set of APIs for creating distributed Java applications that can access a wide variety of services, such as databases, messaging services, and connections to external enterprise systems. End-user clients access these applications using Web browser clients or Java clients. Since J2EE is so widely known we will not discuss it in any more detail here. See the WebLogic Server documentation on programming models for more information.
In addition to the J2EE implementation, WebLogic Server enables enterprises to deploy mission-critical applications in a robust, secure, highly available and scalable environment. These features allow enterprises to configure clusters of WebLogic Server instances to distribute load, and provide extra capacity in case of hardware or other failures. New diagnostic tools allow system administrators to monitor and tune the performance of deployed applications and the WebLogic Server environment itself. You can also configure WebLogic Server to monitor and tune application throughput automatically without human intervention. Extensive security features protect access to services, keep enterprise data secure, and prevent malicious attacks.
Like many other BEA products—and icebergs—WebLogic Server has more below the water line than above it. In particular, WebLogic Server provides a number of features and tools that support the deployment of highly available and scalable applications:
WebLogic Server clusters provide scalability and reliability for your applications by distributing the workload among multiple instances of WebLogic Server. Incoming requests can be routed to a WebLogic Server instance in the cluster based on the volume of work being processed. In case of hardware or other failures, session state is available to other cluster nodes that can resume the work of the failed node. In addition, you can implement clusters so that services may be hosted on a single machine with options to migrate the service to another node in the event of failure.
In addition to replicating HTTP session state across servers within a cluster, WebLogic Server can also replicate HTTP session state across multiple clusters, thereby expanding availability and fault tolerance in multiple geographic regions, power grids, and Internet service providers.
Work Managers prioritize work based on rules you define and monitor actual runtime performance statistics. This information is then used to optimize the performance of your application. Work Managers may be applied globally to a WebLogic Server domain or to a specific application component.
Overload protection gives WebLogic Server the ability to detect, avoid, and recover from overload conditions.
Network channels facilitates the effective use of network resources by segregating network traffic into channels based on the type of traffic.
WebLogic Server persistent store is a built-in, high-performance storage solution for WebLogic Server subsystems and services that require persistence. For example, it can store persistent JMS messages or temporarily store messages sent using the store-and-forward feature. The persistent store supports persistence to a file-based store or to a JDBC-enabled database.
Store-and-forward services enables WebLogic Server to deliver messages reliably between applications that are distributed across WebLogic Server instances. If the message destination is not available at the moment the messages are sent, either because of network problems or system failures, then the messages are saved on a local server instance and are forwarded to the remote destination once it becomes available.
Enterprise-ready deployment tools facilitate deployment and migration of applications from the development phase to a production environment.
Production redeployment enables enterprises to deploy a new version of their application without interrupting work in progress on the older version.
Let's now look at the synergy between these two systems.