Java Reference
In-Depth Information
<service
interface="fancyfoods.offers.SpecialOffer"
ref="romanticOffer" />
<bean
id="romanticOffer"
class="fancyfoods.chocolate.RomanticChocolateOffer" />
Declare OSGi service.
Service implementation.
</blueprint>
The service element declares that a bean should be exposed as an OSG i service, suit-
able for injection into other Blueprint-managed beans or direct lookup. The bean ele-
ment describes a managed bean. Blueprint will take care of instantiating the bean and
initializing it with required properties. In this case, the RomanticChocolateOffer class
doesn't need any external configuration.
CHECKING OUT THE SPECIAL OFFERS
Build the api and chocolate bundles and drop them into the load directory. They'll start
automatically. When you query the chocolate department bundle, you'll see that it has
registered an OSG i service implementing the SpecialOffer interface (figure 2.13).
Annotations and Blueprint
One of the questions we get asked most often about Blueprint is whether it supports
annotations. Java 7 and Spring both support annotation-driven injection of dependen-
cies, and an extension for Aries Blueprint does too. Because annotations aren't part
of the Blueprint standard, we won't cover them; however, we do expect Blueprint
annotations to appear in a future release of the enterprise OSGi specification.
WIRING BLUEPRINT BEANS TOGETHER
Who's going to use this service? Rather than hooking the service right up to our web
bundle, let's make the dependency chain a bit more interesting by adding an Offer-
Aggregator service. The OfferAggregator takes all the available special offers and
works out which ones should be displayed to the user, and in what order. Separating
interface from implementation is always a good idea, so the interface should live in
the api bundle.
Figure 2.13 The bundle details for the chocolate bundle show that it registers an OSGi service
implementing the SpecialOffer interface. A Blueprint container for this bundle is also registered
as a service by the Blueprint implementation.
 
Search WWH ::




Custom Search