Spring Dynamic Modules is a technology that bridges the gap between the Spring Framework and OSGi, combining the simplicity and power of Spring with the modularity, flexibility, and dynamism of OSGi. Spring hardly needs any introduction, being the framework of choice for a significant segment of the Enterprise Java development market. OSGi, in contrast, although not a new technology is one that is just becoming mainstream, helped in no small part by Spring DM.
Spring Dynamic Modules in Action is a cookbook for using Spring DM, but it also serves as a primer for both of the technologies that Spring DM combines. Deciding what we thought you should know, what we thought you might not know but which was essential to further understanding, and what you didn’t know (you are reading this book, after all!) proved quite tricky. In the end, we decided to cover the basics of Spring, because some readers will be OSGi users wanting to understand Spring DM, and we decided to provide a little more detail on OSGi, because many more readers will be Spring users wanting to understand Spring DM. If you are comfortable with either or both of these technologies, you can safely skip over the first couple of chapters.
Another problem for us was the breadth of technologies covered by Spring that could be supported in an OSGi environment. There are already numerous books covering Spring in general, and also particular elements of the “Spring portfolio.” As a result, in chapters dealing with these technologies we’ve focused on how to make them work using Spring DM, rather than offering a more general discussion of the features offered by the technologies. Likewise, some of the features of Spring DM support OSGi features (such as compendium services), the scope of which is too broad to be covered in this book. So again we have limited ourselves to describing the feature briefly and then focusing on its use in Spring DM. If you read these sections and find you want to know more, rest assured that further information is freely available in the various Spring reference manuals (www.springframework.org) and the OSGi set of specifications (www.osgi.org).
The main exception to this general approach is the discussion of web applications. Spring DM 1.2 includes extensive support for web applications, and we felt that the topic deserved a greater depth of coverage. But as with all new technologies, the state of the art can move very quickly, and when we were halfway through writing this book, the web support was deprecated for Spring DM 2.0 in favor of RFC 66 as implemented by Spring dm Server. Then, toward the end of the writing process, the Eclipse Gemini project was started, with Spring DM moving to this project; right at the end, dm Server itself was transitioned to Gemini as the Eclipse Virgo project. This technological shape-shifting would have been impossible to track accurately in the book, so we finally decided to stay with our discussion of Spring DM 1.2.
Because this is an “in Action” book, we have striven to provide code and configuration examples throughout, both to illustrate the concepts and to provide a template for successful operation.
Our primary target audience for this book is Spring developers and architects who want to discover what OSGi can do. Spring Dynamic Modules is about using Spring in an OSGi runtime environment, so if you want to write Spring-based applications on the OSGi platform, this is the book for you.
But we aren’t so naive as to assume that everyone is working on enterprise applications using Spring; some people have been using OSGi for years, creating all kinds of applications, and they may have barely heard about the Spring Framework—the popular dependency-injection framework that has helped developers build so many applications. So the reverse is also true: if you want to build OSGi applications using the Spring Framework, this book is also for you!
The book is divided into three parts. The first covers the basics of Spring DM, Spring, and OSGi. The second part forms the core of the discussion of Spring DM’s features. The final part covers more advanced topics, including advanced configuration, testing, and the Blueprint specification. We also included several appendixes covering tooling support for Spring DM development.
Chapter 1 discusses Java modularity in general—after all, OSGi and Spring DM are primarily technologies that enable modularity—and also Spring, OSGI, and Spring DM. The concepts covered are reinforced in later chapters, so if you want to get the flavor of the whole book, chapter 1 is a good place to start.
Chapter 2 is an OSGi primer, and it introduces the main building blocks of OSGi: bundles, wiring, and services. It also covers topics such as native code and error handling.
Chapter 3 then relates OSGi concepts to an overview of Spring DM features, covering the main facets such as the application context, dependencies, Spring extender, osgi namespace, container provisioning, fragment configuration, and application development using Maven.
Chapter 4 covers the operation of the two extenders that Spring DM provides: the standard extender and the web extender.
Chapter 5 covers the use of OSGi services with Spring DM. Because service support is integral to the feature set provided by Spring DM, this chapter is one of the pivotal chapters of the book.
Chapter 6 covers the development of enterprise applications using Spring DM and, in particular, how to design and structure applications of this type to take advantage of all the power that Spring DM and OSGi provide. The chapter also covers the integration of third-party enterprise libraries into an OSGi environment.
Chapter 7 covers the use of JDBC and JPA in Spring DM-enabled applications.
Chapter 8 covers the use of common web frameworks in Spring DM-enabled applications.
Chapter 9 covers some advanced topics, including configuration of the Spring DM container and some Spring DM patterns that have proved useful in real products that use Spring DM.
Chapter 10 covers the testing of OSGi applications that use Spring DM.
Chapter 11 discusses Spring DM’s support for OSGi compendium services, in particular configuration admin and eventing.
Chapter 12 covers the OSGi Blueprint specification and its relationship to Spring DM.
The source code for the example applications in this book has been donated to the Apache Software Foundation. This source code is available at http://code.google.com/p/springdm-in-action/ and is also freely available from Manning’s website, www.manning.com/SpringDynamicModulesinAction.
Much of the source code shown in the book consists of fragments designed to illustrate the text. When a complete segment of code is given, it is shown as a numbered listing; code annotations accompany some listings. When we present source code, we sometimes use a bold font to draw attention to specific elements.
In the text, Courier typeface is used to denote code (Java and XML) as well as Java methods, XML element names, and other source code identifiers:
<action>).Purchase of Spring Dynamic Modules in Action includes free access to a private web forum run by Manning Publications where you can make comments about the book, ask technical questions, and receive help from the lead author and from other users. To access the forum and subscribe to it, point your web browser to www.manning.com/SpringDynamicModulesinAction. This page provides information on how to get on the forum once you are registered, what kind of help is available, and the rules of conduct on the forum.
Manning’s commitment to our readers is to provide a venue where a meaningful dialogue between individual readers and between readers and the author can take place. It is not a commitment to any specific amount of participation on the part of the author, whose contribution to the AO remains voluntary (and unpaid). We suggest you try asking the author some challenging questions lest his interest stray! The Author Online forum and the archives of previous discussions will be accessible from the publisher’s website as long as the book is in print.