3.4 A Guide to Forming Bundles

So what makes an application suitable for deployment on the Virgo Server for Apache Tomcat? Since OSGi is at the heart of the VTS, modular applications consisting of bundles, which each represent distinct functionality and well-defined boundaries, can take maximum advantage of the OSGi container’s capabilities. The core ideas behind forming bundles require following good software engineering practices: separation of concerns, loose coupling, and communication through clear interfaces. In this section, we look at a few approaches that you may use to create modular applications for Virgo Server for Apache Tomcat deployment. Please consider the following discussion as guidelines and not as rules.

Bundles can be formed along horizontal slices of layering and vertical slices of function. The objective is to enable independent development of each bundle and minimize the skills required to develop each bundle.

For example, an application could have the following bundles: infrastructure, domain, repository, service, and web as shown in the following diagram.

Each bundle consists of types appropriate for that layer and exports packages and services to be used by other layers. Let’s examine each bundle in more detail:

Table 3.2. Bundles across layers

BundlesImported PackagesExported PackagesConsumed ServicesPublished Services
InfrastructureThird-party librariesInfrastructure interfacesNoneNone
DomainDepends: for example, if JPA is used to annotate persistent types, then JPA packages.Public domain typesNoneNone
WebDomain, ServiceNoneService beansNone
ServiceDomain, Infrastructure, RepositoryService interfacesRepository beansService beans
RepositoryDomain, Third-party libraries, ORM bundles, etc.Repository interfacesDataSources, ORM session/entity managers, etc.Repository beans


Within each layer, you may create bundles for each subsystem representing a vertical slice of business functionality. For example, as shown in the following figure, the service layer is divided into two bundles each representing separate business functions.

You can similarly separate the repositories, domain classes, and web controllers based on the business role they play.