C H A P T E R 6
■ ■ ■
Spring in the Enterprise
In this chapter, you will learn about Spring's support for three common technologies on the Java EE
platform: Java Management Extensions (JMX) , sending e-mail, and scheduling tasks.
JMX is a technology for managing and monitoring system resources such as devices, applications,
objects, and service-driven networks. The specification is powerful for the management of systems at
runtime and for adapting legacy systems. These resources are represented by managed beans (MBeans) .
Originally, JMX was distributed separately, but it has been part of Java SE since version 5.0. JMX has seen
many improvements, but the original specification for JMX_JSR 03_is very old! Spring supports JMX by
allowing you to export any Spring beans as model MBeans (a kind of dynamic MBean ), without
programming against the JMX API. In addition, Spring enables you to access remote MBeans easily.
JavaMail is the standard API and implementation for sending e-mail in Java. Spring further provides
an abstract layer for you to send e-mail in an implementation-independent fashion.
There are two main options for scheduling tasks on the Java platform: JDK Timer and Quartz
Scheduler ( http://www.opensymphony.com/quart z/ ). JDK Timer offers simple task scheduling features
that you can use conveniently because the features are bundled with JDK. Compared with JDK Timer,
Quartz offers more powerful job scheduling features. For both options, Spring supplies utility classes
for you to configure scheduling tasks in the bean configuration file, without programming against
Upon finishing this chapter, you will be able to export and access MBeans in a Spring application. You
will also be able to utilize Spring's supporting features to simplify sending e-mail and scheduling tasks.
6-1. Exporting Spring Beans as JMX MBeans
You want to register an object from your Java application as a JMX MBean to allow management and
monitoring. In this sense, management is the capability to look at services that are running and
manipulate their runtime state on the fly. Imagine being able to do these tasks from a web page: rerun
batch jobs, invoke methods, and change configuration metadata that you'd normally be able to do only
at runtime. However, if you use the JMX API for this purpose, a lot of coding will be required, and you'll
have to deal with JMX's complexity.