public interface OsgiApplicationContextCreator
class HeaderBasedAppCtxCreator implements OsgiApplicationContextCreator { /** location header */ private static final String HEADER = "Context-Locations"; public DelegatedExecutionOsgiBundleApplicationContext createApplicationContext(BundleContext bundleContext) { Bundle owningBundle = bundleContext.getBundle(); Object value = owningBundle.getHeaders().get(HEADER); String[] locations = null; if (value != null && value instanceof String) { locations = StringUtils.commaDelimitedListToStringArray((String) value); } else { locations = <default values> } // create application context from 'locations' return applicationContext; } }Note: The application contexts should be only created and initialized but not started (i.e.
refresh()
method should not be called).
The recommended way of configuring the extender is to attach any relevant
OsgiApplicationContextCreator
implementation as fragments to
extender bundle. Please see the OSGi specification and Spring-DM reference
documentation for more information on how to do that.
Note the extender also supports OsgiBeanFactoryPostProcessor
for
application context customization.
The creation of an application context doesn't guarantee that a bundle
becomes Spring-DM managed. The Spring-DM extender can do additional post
filtering that can discard the bundle (and associated context).Modifier and Type | Method and Description |
---|---|
DelegatedExecutionOsgiBundleApplicationContext |
createApplicationContext(org.osgi.framework.BundleContext bundleContext)
Creates an application context for the given bundle context.
|
DelegatedExecutionOsgiBundleApplicationContext createApplicationContext(org.osgi.framework.BundleContext bundleContext) throws Exception
null
should be
returned. Exceptions will be caught and logged but will not prevent the
creation of other application contexts.bundleContext
- OSGi bundle context determining the context creationnull
if no context should be created, non-
null
otherwiseException
- if something goes wrongCopyright © 2006–2014. All rights reserved.