Tải bản đầy đủ (.pdf) (543 trang)

Spring Dynamic Modules in Action potx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (6.03 MB, 543 trang )

MANNING
Arnaud Cogoluègnes
Thierry Templier
Andy Piper
F
OREWORD

BY
P
ETER
K
RIENS
www.it-ebooks.info
Spring Dynamic Modules in Action
www.it-ebooks.info
www.it-ebooks.info
Spring Dynamic
Modules in Action
ARNAUD COGOLUÈGNES
THIERRY TEMPLIER
ANDY PIPER
MANNING
Greenwich
(74° w. long.)
www.it-ebooks.info
For online information and ordering of this and other Manning books, please visit
www.manning.com. The publisher offers discounts on this book when ordered in quantity.
For more information, please contact
Special Sales Department
Manning Publications Co.
180 Broad Street


Suite 1323
Stamford, CT 06901
Email:
©2011 by Manning Publications Co. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in
any form or by means electronic, mechanical, photocopying, or otherwise, without prior written
permission of the publisher.
Many of the designations used by manufacturers and sellers to distinguish their products are
claimed as trademarks. Where those designations appear in the book, and Manning
Publications was aware of a trademark claim, the designations have been printed in initial caps
or all caps.
Recognizing the importance of preserving what has been written, it is Manning’s policy to have
the books we publish printed on acid-free paper, and we exert our best efforts to that end.
Recognizing also our responsibility to conserve the resources of our planet, Manning books are
printed on paper that is at least 15 percent recycled and processed without the use of elemental
chlorine.
Development editor: Cynthia Kane
Manning Publications Co. Copyeditor: Andy Carroll
180 Broad Street, Suite 1323 Cover designer: Marija Tudor
Stamford, CT 06901 Typesetter: Gordan Salinovic
ISBN 9781935182306
Printed in the United States of America
12345678910 –MAL –151413121110
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
v
brief contents
PART 1 SPRING DM BASICS. 1
1 ■ Modular development with Spring and OSGi 3
2 ■ Understanding OSGi technology 24

3 ■ Getting started with Spring DM 63
PART 2 CORE SPRING DM . 101
4 ■ Using Spring DM extenders 103
5 ■ Working with OSGi services 133
6 ■ OSGi and Spring DM for enterprise applications 164
7 ■ Data access in OSGi with Spring DM 199
8 ■ Developing OSGi web components with Spring DM and
web frameworks 236
PART 3 ADVANCED TOPICS 281
9 ■ Advanced concepts 283
10 ■ Testing with Spring DM 323
11 ■ Support for OSGi compendium services 351
12 ■ The Blueprint specification 374
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
vii
contents
foreword xv
preface xvii
acknowledgments xix
about this book xxi
about the authors xxv
about the title xxvi
about the cover illustration xxvii
PART 1 SPRING DM BASICS 1
1
Modular development with Spring and OSGi 3
1.1 Java modularity 4

What is modularity and what is it good for? 4

Java—the end
and the beginning 4

Are your applications really modular? 5
1.2 The Spring Framework 5
Loose coupling of classes 6

Dependency injection 7

Aspect-
oriented programming (AOP) 8

Enterprise support 9
1.3 A new approach to modular development with OSGi 10
Aims of OSGi 10

OSGi layers 11

What OSGi offers 12
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
CONTENTS
viii
1.4 Using Spring in an OSGi environment with Spring DM 13
What is Spring DM? 13

Embedding Spring within an OSGi
container 15


Benefits of Spring DM for real-life OSGi
applications 17
1.5 Spring DM Hello World 18
Provisioning the OSGi container 18

Writing the Spring DM–
powered bundle 21

Deploying the bundle 22
1.6 Summary 23
2
Understanding OSGi technology 24
2.1 OSGi components 25
Component structure 25

Component configuration 26
OSGi containers 28

OSGi component lifecycle 29
2.2 Component dependencies 30
Classloader isolation and chaining 31

Providing dependencies 33
Consuming dependencies with the Import-Package header 34
Consuming dependencies with the Require-Bundle header 36
Matching and versioning 38
2.3 Interacting with the OSGi container 42
Bundles 43


Lifecycle management 44

Properties 46

Event
support 46

Persistent storage area 48

Bundle activator 48
2.4 Service support in OSGi 50
Providing services 51

Using services 54

Service event support 56
2.5 Handling native code 58
2.6 Diagnosing errors 59
Detecting components with problems 60

Detecting different kinds
of problems 61
2.7 Summary 62
3
Getting started with Spring DM 63
3.1 Using Spring in OSGi components 64
Embedding the Spring application context within components 64
Spring DM’s OSGi-aware application context 66

Spring DM’s

extender mechanisms 67

Kinds of supported bundles 69
Spring DM’s osgi namespace 70
3.2 Installing Spring DM 72
Configuring a container 72

Provisioning a container for simple
use 73

Provisioning a container for web use 76
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
CONTENTS
ix
3.3 Using a fragment to configure the LOG4J bundle 80
Using the fragment configuration pattern 80

Implementing a
fragment 81

Installing a fragment into the OSGi container 82
3.4 Developing Spring DM bundles 82
Creating and configuring a bundle 82

Packaging a bundle 85
Checking a bundle within a container 86

Developing an
integration test 87

3.5 Developing Spring DM web bundles 94
Creating and configuring a web bundle 94

Packaging a web
bundle 95

Checking the operation of a web bundle in a container 97
Developing an integration test for a web bundle 97
3.6 Summary 100
PART 2 CORE SPRING DM 101
4
Using Spring DM extenders 103
4.1 Unleashing Spring DM’s standard extender 104
A word about dependencies 104

Structure of standard Spring
OSGi components 106

Initializing and destroying the Spring
container 110

Customizing application context creation 116
Listening to extender events with the whiteboard pattern 118
Hard dependencies on the OSGi environment 123
4.2 Unleashing Spring DM’s web extender 126
Structure of Spring DM web OSGi components 126

Classloading
in web bundles 127


OSGi-aware Spring web container 129
Spring DM web deployer 131
4.3 Summary 132
5
Working with OSGi services 133
5.1 Dependency injection and OSGi services 134
Combining OSGi services and dependency injection 134

XML-
based registration and referencing 136

Annotation-based service
referral 139
5.2 The thread context classloader and its use in OSGi 141
Using the thread context classloader 141

Using the thread
context classloader with OSGi 142
5.3 Advanced OSGi service configuration 144
Configuration for registering services 144

Configuration for
referencing services 148
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
CONTENTS
x
5.4 Handling OSGi service dynamics 151
Service registration and unregistration events 152


Service bind
and unbind events 153
5.5 Handling collections of OSGi services 156
Configuring collections 156

Sorting collections 157

Greedy
proxying 159

Integrated support when collections are updated 160
5.6 Programmatic service support 160
Registering a service programmatically 161

Referencing services
programmatically 162

ServiceReference support 162
5.7 Summary 163
6
OSGi and Spring DM for enterprise applications 164
6.1 Building an OSGi repository for enterprise applications 165
Using Java and Java EE frameworks in OSGi environments 165
Choosing the right frameworks for OSGi 166

Getting OSGi-ready
artifacts 168
6.2 OSGi-ifying libraries and frameworks 169
How to create OSGi-ified versions of libraries 169


Converting by
hand 172

Converting using tools 173

Packaging your own
modules as OSGi bundles 180
6.3 Designing OSGi enterprise applications 180
Organizing OSGi components 181

Defining interactions
between application bundles 187
6.4 How Spring DM handles OSGi applications’ dynamic
behavior 189
Dealing with the appearance or disappearance of services 189
Providing a new version of a component 195
6.5 Summary 198
7
Data access in OSGi with Spring DM 199
7.1 Using JDBC within OSGi with Spring DM 200
JDBC concepts 200

JDBC issues when used within OSGi 202
Configuring JDBC data sources 203

Provisioning the OSGi container
for JDBC 207

Using JDBC within OSGi with Spring DM 207
7.2 Using ORM within OSGi with Spring DM 209

Object/relational mapping 210

Load-time weaving 215
Provisioning a container for JPA implementations 218

Using JPA in
OSGi with Spring DM 220

JPA implementation specifics when used
with Spring DM 223

A JPA summary 226
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
CONTENTS
xi
7.3 Transactions 227
Spring’s transactional support 227

Using JPA transactions with
Spring DM 229
7.4 Using the open EntityManager in view pattern 232
The open EntityManager in view pattern 232

Using the open
EntityManager in view pattern with Spring DM 233
7.5 Summary 235
8
Developing OSGi web components with Spring DM and web
frameworks 236

8.1 Using action-based web frameworks with Spring DM 237
Using Spring DM with action-based frameworks 237

Using
Spring MVC with Spring DM 238
8.2 Using component-based web frameworks with Spring DM 244
Using Spring DM with component-based frameworks 244

Using
JSF with Spring DM 245

Using Wicket with Spring DM 251
8.3 Using AJAX frameworks with Spring DM 256
Using Spring DM with AJAX frameworks 257

Using DWR with
Spring DM 257

Using GWT with Spring DM 262
8.4 Using web services with Spring DM 267
Using Spring DM with web service frameworks 267

Using Spring
WS with Spring DM 268

Using Restlet with Spring DM 273
8.5 Summary 279
PART 3 ADVANCED TOPICS 281
9
Advanced concepts 283

9.1 Configuring Spring DM core components 284
Fragment-based configuration 285

Features configurable
through named beans 285
9.2 Extending the standard extender 286
Beans usable for configuration 287

Task executor for creating
application contexts 288

Task executor for destroying application
contexts 290

Extender properties 291

Propagating application
context events 292

Overriding application context creation 293
Adding postprocessing to application contexts 297

Overriding the
default OSGi application context listener 298

How SpringSource
dm Server customizes Spring DM’s extender 298
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
CONTENTS

xii
9.3 Extending the web extender and WAR deployer 300
Beans available for configuration 300

Overriding the WAR
deployer 301

Overriding the context path strategy 301
Overriding the WAR scanner 302
9.4 Configuring embedded web containers 303
The basics of Spring DM’s web support 303

Support for
Tomcat 305

Support for Jetty 308
9.5 Support for Java 2 security 311
The Java security model 311

The OSGi security model 313
Integrating Spring DM into the OSGi security model 315
9.6 Advanced patterns 316
Implementation provider pattern 316

Chained classloader
pattern for proxy-based AOP 319
9.7 Summary 321
10
Testing with Spring DM 323
10.1 Testing OSGi components with Spring DM 324

General concepts 324

Unit tests with Spring-based
applications 325

Testing OSGi components 327
10.2 Strict unit tests for OSGi components 330
Spring DM’s OSGi mocks 330

Spring DM’s OSGi mocks in
action 331
10.3 Integration tests for OSGi applications 335
Developing integration tests with Spring DM support 335
Advanced features of Spring DM test support 344
10.4 Summary 350
11
Support for OSGi compendium services 351
11.1 Overview of compendium services 352
What are compendium services? 352

Spring DM’s support for
compendium services 353
11.2 Spring DM’s Configuration Admin Service support 355
OSGi Configuration Admin Service 356

Using properties
defined by the Configuration Admin Service 358

Support of
managed entities 360

Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
CONTENTS
xiii
11.3 Spring DM’s Event Admin Service support 365
OSGi Event Admin Service 365

Linking Spring DM and the OSGi
Event Admin Service 367

Implementing the bridge between Spring DM
and Event Admin Service 369

Implementing OSGi event
handlers 371
11.4 Summary 372
12
The Blueprint specification 374
12.1 Standardization of Spring DM 375
The attraction of open standards 375

Standards
development 376

Goals of the Blueprint
specification 376

Scope of the specification 377
12.2 A taxonomy of Blueprint 377
A Blueprint example 378


Blueprint bundles 379
12.3 Blueprint manager syntax 379
Bean manager 379

Service manager 381

Reference
manager 382

Reference-list manager 383

A Blueprint
example 384

The Blueprint container and its
metadata 385

Environment managers 387
12.4 Runtime support and lifecycle 388
Blueprint lifecycle 388

Type converters 392
12.5 Using Spring DM with Blueprint 394
12.6 Summary 394
appendix A Spring DM development with Eclipse 397
appendix B OSGi development with Maven 2 419
appendix C Spring DM development with Ant and Ivy 458
appendix D OSGi development with the Pax tools 474
index 499

Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
xv
foreword
It must have been in 2006 that I got a call as OSGi’s Technical Director from Adrian
Colyer, CTO of Interface21, the company that was the source of the Spring Frame-
work. Yes, I’d heard of the Spring Framework, and I understood that it was a great
improvement over existing techniques for writing software for the enterprise. As a
developer who had gained most of his experience in developing embedded and mid-
dleware applications, I found all that XML rather foreign. However, I’d noticed the
enterprise world’s interest in OSGi, so I too was interested.
It turned out that Interface 21, BEA, and Oracle were considering creating support
for OSGi in the Spring Framework. Spring is very good at configuring an application
built out of simple objects that use, among other things, the simplified Spring inter-
faces to communicate with the world. However, Spring did not provide any support
for modularity. In contrast, OSGi provides strong modularity support but it’s not
strong in configuration and it had no services in the enterprise space. This was a
match made in heaven!
To discuss supporting OSGi in Spring, Adrian proposed a conference call with Hal
Hildebrand (Oracle), John Wells (BEA), and one of the authors of this book: Andy
Piper (BEA). B.J. Hargrave (IBM) also attended as OSGi’s CTO. The initial conference
call was followed by a meeting in London at the offices of BEA. It was a meeting I’ll
always remember, it was the start of what became Spring DM. At first, I felt that the
group saw OSGi as something that needed to be supported by Spring; that is, as one of
many things to be supported. As the meeting progressed, it became clear how nice the
combination of Spring and OSGi could be; there was a lot of synergy and surprisingly
little overlap. At the end of the meeting, we were thrilled with this project's potential.
Download from Wow! eBook <www.wowebook.com>

www.it-ebooks.info
FOREWORD
xvi
The Spring DM project became crucial for the adoption of OSGi in the enterprise
space. At that time, OSGi had been adopted by Eclipse, which made it acceptable for
general programming. However, the enterprise space is conservative and was hesitant
about adopting OSGi. The fact that Interface21 people started to sell OSGi at the many
conferences they visited helped to give OSGi a place in the enterprise world. That said,
it was a surprise for me when Interface21 changed their name to SpringSource and
put a lot of emphasis on the OSGi connection. They quickly became a member of the
OSGi Alliance and started RFC 124, as an endeavor to put Spring DM under the OSGi
flag. This RFC later turned into the Blueprint specification. SpringSource also intro-
duced the dm Server (now project Gemini in Eclipse) and more importantly, they
launched the OSGi Bundle Repository, filling a crucial gap for the acceptance of OSGi
in the enterprise. This repository contained bundles based on open source projects.
Before this repository, developers were forced to create their own bundles from open
source projects, and this was not always painless.
Alas, it still is not always painless. The core principle of OSGi is modularity, creat-
ing inside and outside spaces with well-defined ports. The advantages of modularity
are numerous and well proven. However, OSGi enforces those rules strictly on all lev-
els. Unfortunately, it turns out that many open source libraries do not live well inside
modules—thay need global visibility of all classes. Over the past decade, mainstream
Java has given rise to a number of patterns that appear to be modular but are not so
in reality.
That’s why this book about Spring DM and Blueprint is so crucial. First, it provides
an excellent introduction to OSGi and what the guiding principles are. As one of the
participants of the OSGi specification, I do not think I could have improved on this
description. The book then explains how you should structure your projects with
Spring DM, but it doesn’t stop there. It doesn’t hide the complexities of today’s reality,
which is that you have to use existing (open source) libraries. It provides an extensive

description of what you should do when you need to use libraries that do not play well
in a modular world.
If you’re already building applications using Spring, then read this book and take
the leap into the OSGi world. Although you might run into some hurdles, this book
will help you solve them, and the rewards are well worth it.
PETER KRIENS
OSGI TECHNICAL DIRECTOR
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
xvii
preface
We all dream of the perfect software program.
You know the one—it’s composed of multiple modules, each in charge of a spe-
cific, tightly defined set of tasks, each uniquely simple and elegant, interacting harmo-
niously to achieve the complex ends required by the user. We are taught in school how
to build these perfect programs using techniques such as object-oriented program-
ming and aspect-oriented programming. These techniques work well, but the end
goal is always to make the system more reliable, more testable, more complete, and
more flexible by making it more modular so that the whole is greater than the sum of
the parts.
Of course, most of the software programs we work with are not perfect—have you
encountered any of these issues?

The big, bad application problem Your application is 600 MB in size and it takes 10
minutes to repackage one Java class and 20 minutes to deploy to your favorite
application server. When you do finally get it to deploy, you find you’ve made a
mistake and now you have to undeploy, fix, and redeploy—all outside of office
hours—missing the soccer and poker night with your mates.

The brittle-change problem A high-profile customer reports a problem, so you

quickly fix the code and try to rebuild the application, only to find that the appli-
cation won’t build because another component is using the internal function you
just changed. When you finally get the application built and deployed, you start
getting reports of other parts of the application that are malfunctioning. Work-
ing into the night—again missing the soccer game—you discover that the
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
PREFACE
xviii
change you made had unforeseen consequences that could only be discovered
by running the full QA suite—a process that takes 48 hours.

The build-the-world problem Your development team is in Beijing, Mumbai, and
San Ramon, and each subteam works on different parts of the application in dif-
ferent time zones and on different development schedules. As the team and appli-
cation grow, you find that it becomes increasingly hard to keep the different parts
of the product separate—any time you make a change, you find it impossible to
tell which teams will be affected by your changes. The only solution is to keep all
the teams on exactly the same version of the application, and to rebuild and retest
the entire product every time any change is made. You eventually spend all of your
time building and testing the product and none actually developing it. The com-
pany goes bankrupt, you lose your job, and now you have plenty of time to watch
soccer—if only your widescreen TV hadn’t been repossessed.
These problems are all symptoms of unmodular applications.
As authors, we come from different but related, backgrounds. Arnaud and Thierry
come from the enterprise application development sphere, and Andy comes from a
middleware product development background, thanks to his jobs at BEA and then Ora-
cle. But we all share the same enthusiasm and passion for Spring technologies and for
anything that can help us build better software. Arnaud remembers his first contact
with Spring Dynamic Modules—he attended Costin Leau’s (Spring Dynamic Modules’

project lead) talk at SpringOne Europe in 2008. What could be more exciting for a
Spring enthusiast than to be able to use Spring on the OSGi platform? At last, real, run-
time modularity meets Spring! Unfortunately, there was not, at the time, much in the
way of resources around Spring Dynamic Modules. That was when he met Thierry and
they both went on to write a French book on Spring. In contrast, Andy in 2008 had
already been working with Spring Dynamic Modules for a couple of years, having been
involved with its original development and having used it extensively on several BEA
products. It was later in 2009 that Manning Publications contacted Arnaud and Thierry
to suggest writing a proposal for a Spring Dynamic Modules in Action book.
Working with Manning can be difficult: they have high standards for their books,
and we had no idea how high the mountain would turn out to be when we wrote that
proposal, which then passed a succession of reviews. Some reviewers were happy with
it, but others were tough, like that Oracle guy, Andy Piper. But his remarks were con-
structive, and based on his feedback Manning suggested that he be involved in the
writing process. After all, if you want something done right, you do it yourself! Having
a native English speaker on the writing team also proved useful, as some say that the
French accent comes across even in written text.
We have done our best to make this book as comprehensive and accessible as pos-
sible. We hope you’ll benefit from our experience with the Spring Framework, OSGi,
and in making both worlds cohabit as harmoniously as possible using Spring DM. We
believe that these technologies are an important piece of the puzzle in bringing your
applications closer to the mythical “perfect” program.
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
xix
acknowledgments
We thank the team at Manning for their hard work through the process of writing the
book. Michael Stephens first contacted us and helped us create the book proposal.
Marjan Bace gave us the opportunity to write the book and provided us with valuable
advice about its structure. Karen Tegtmeyer organized the reviews, which resulted in

further improvements. Last, but not least, thanks to our development editor, Cynthia
Kane, who helped us improve the book’s writing and structure.
Thanks to all the reviewers who took the time to read the book and make construc-
tive remarks about its content. Their feedback was essential in keeping us on the right
track: David Dossot, Gildas Cuisinier, Jawher Moussa, John Guthrie, Peter Pavlovich,
Jos Dirksen, Denys Kurylenko, Dmitry Sklyut, Edmon Begoli, Marco Ughetti, Deepak
Vohra, Rob Harrop, and Jeroen Benckhuijsen.
This book is about an open source project, so it would not exist were it not for the
efforts of the people who spent their time creating and making Spring Dynamic Mod-
ules live. Thanks to all the Spring DM team: Adrian Colyer, Hal Hildebrand, and, of
course, Costin Leau, the project’s lead. An open source project is also a community
project, so thanks to everyone who contributed to the project by answering questions
on the forum or by participating in the bug-tracking process. This also helped us to
learn more about how people use Spring DM.
A very special thanks to Peter Kriens, the director of technology at the OSGi Alli-
ance, who carefully reviewed the book and wrote the foreword.
Our technical proofreader, Loïc Simon, helped us produce a more accurate and
polished book. Thank you for your contribution Loïc!
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
ACKNOWLEDGMENTS
xx
ARNAUD COGOLUÈGNES
Many thanks to all the people around me for their patience and understanding once I
got absorbed in this project. Thanks to my manager at Zenika, Carl Azoury, who pro-
vided me with some time during my day-to-day job to work on the book. And thanks to
Claire, who had the patience to put up with my writing two books in a row.
THIERRY TEMPLIER
I am grateful to my beloved wife Séverine for her confidence and her support and for
being by my side in life.

ANDY PIPER
Being involved in Spring DM from the start has been a wild ride, and I thank (again)
the gang at SpringSource for their help and patience with my sometimes strange
requirements, in particular Rod Johnson and Adrian Colyer, who have always been
professional, courteous, and friendly in our interactions. My fellow authors, Arnaud
and Thierry—who did the bulk of the writing—were invaluable with their contribu-
tions and intelligent insight; I could not have done it without them. Thanks also to
Oracle for giving me sufficient time for the project. Finally, my gratitude extends to
my long-suffering family for putting up with my many projects, although I can’t prom-
ise this will be my last book!
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
xxi
about this book
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 modu-
larity, 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 cov-
ering 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
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
ABOUT THIS BOOK
xxii
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 configura-
tion examples throughout, both to illustrate the concepts and to provide a template
for successful operation.
Who should read this book
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 applica-
tions 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 pop-
ular dependency-injection framework that has helped developers build so many appli-
cations. So the reverse is also true: if you want to build
OSGi applications using the
Spring Framework, this book is also for you!
Roadmap
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, test-
ing, 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.
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
ABOUT THIS BOOK

xxiii
Chapter 2 is an OSGi primer, and it introduces the main building blocks of OSGi: bun-
dles, 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, cover-
ing 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 integra-
tion 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 partic-
ular configuration admin and eventing.
Chapter 12 covers the
OSGi Blueprint specification and its relationship to Spring DM.
Code
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 web-
site, www.manning.com/SpringDynamicModulesinAction.
Much of the source code shown in the book consists of fragments designed to illus-
trate 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:

A reference to a method in the text will generally not include the signature,
because there may be more than one form of the method call.

A reference to an XML element in the text will include the braces but not the
properties or closing tag (for example,
<action>
).
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info
ABOUT THIS BOOK

xxiv
Author online
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.man-
ning.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.
Download from Wow! eBook <www.wowebook.com>
www.it-ebooks.info

×