The Resource abstraction

The Spring Framework defines a resource abstraction for loading resources within an application context (see Spring's resource abstraction). All resource loading is done through the org.springframework.core.io.ResourceLoader associated with the application context. The org.springframework.core.io.ResourceLoader is also available to beans wishing to load resources programmatically. Resource paths with explicit prefixes - for example "classpath:" are treated uniformly across all application context types (for example, web application contexts and classpath-based application contexts). Relative resource paths are interpreted differently based on the kind of application context being created. This enables easy integration testing outside the ultimate deployment environment.

OSGi 4.0.x specification defines three different spaces from which a resource can be loaded. Spring-DM supports all of them through its dedicated OSGi-specific application context and dedicated prefixes:

Table 3.1. OSGi resource search strategies

OSGi search strategyprefixExplanation
Class Spaceclasspath:Search the bundle classloader (the bundle and all imported packages). Forces the bundle to be resolved.
JAR File (or JarSpace)osgibundlejar:Search only the bundle jar. Provides low-level access without requiring the bundle to be resolved.
Bundle Spaceosgibundle:Search the bundle jar and its attached fragments (if there are any). Will never create a class loader or resolve the bundle.

Please consult section 4.3.12 of the OSGi specification for an in depth explanation of the differences between them.

Note that if no prefix is specified, the bundle space will be used.

All of the regular Spring resource prefixes such as file: and http: are also supported, as are the pattern matching wildcards. Resources loaded using such prefixes may come from any location, they are not restricted to being defined within the resource-loading bundle or its attached fragments.

OSGi platforms may define their own unique prefixes for accessing bundle contents. For example, Equinox defines the bundleresource: and bundlentry: prefixes). These platform specific prefixes may also be used with Spring OSGi, at the cost of course of tying yourself to a particular OSGi implementation.