Spring Dynamic Modules

Aus Eniak

Wechseln zu: Navigation, Suche

Spring Dynamic Modules for OSGi(tm) Service Platforms (so der vollständige Name dieses Projektes) soll es ermöglichen Spring Anwendungen in einem OSGi Framework laufen zu lassen.

Wichtige Methoden

Wandelt ein BundleEvent in den Namen des Events um (STARTING, STARTED, STOPPING, ...):

OsgiStringUtils.nullSafeToString(bundleEvent)

Kleines Beispiel

Um das kleine Spring-DM Beispiel „simple-service-bundle“ zum Laufen zu kriegen muss man folgende Bundles bereitstellen:

Bild:Spring-DM-config.png

Diese Bundles erfüllen quasi die Minimalanforderungen. Zu beachten ist, dass beim Download von Spring-OSGi Milestone 3 das Bundle „aopalliance.osgi-1.0-SNAPSHOT.jar“ fehlt. Es muss am besten mit Maven selber gebaut werden. Dazu Quellen runterladen und mvn clean install eingeben.

Die Konsole von Equinox sieht dann so aus (das Problem mit log4j konnte ich noch nicht lösen):

osgi> 2007-10-11 18:11:59,490  INFO (ContextLoaderListener.java:313) Starting org.springframework.osgi.extender bundle v.[1.0.0.m3]
2007-10-11 18:11:59,583  INFO (AbstractApplicationContext.java:395) Refreshing org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext@97a560: display name [OsgiBundleXmlApplicationContext(bundle=org.springframework.osgi.samples.simpleservice, config=bundle-jar:/META-INF/spring/*.xml)]; startup date [Thu Oct 11 18:11:59 CEST 2007]; root of context hierarchy
2007-10-11 18:11:59,646  INFO (XmlBeanDefinitionReader.java:293) Loading XML bean definitions from OSGi res[/META-INF/spring/simpleservice-osgi.xml|id=32|symName=org.springframework.osgi.samples.simpleservice]
2007-10-11 18:11:59,802  INFO (XmlBeanDefinitionReader.java:293) Loading XML bean definitions from OSGi res[/META-INF/spring/simpleservice.xml|id=32|symName=org.springframework.osgi.samples.simpleservice]
2007-10-11 18:11:59,817  INFO (AbstractApplicationContext.java:410) Bean factory for application context [org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext@97a560]: org.springframework.beans.factory.support.DefaultListableBeanFactory@104c575
2007-10-11 18:11:59,849  INFO (DefaultListableBeanFactory.java:370) Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@104c575: defining beans [simpleServiceOsgi,simpleService]; root of factory hierarchy
2007-10-11 18:11:59,880  INFO (OsgiServiceFactoryBean.java:351) Publishing service under classes [{org.springframework.osgi.samples.simpleservice.MyService}]
2007-10-11 18:11:59,880  INFO (AbstractOsgiBundleApplicationContext.java:265) Publishing application context with properties (org.springframework.context.service.name=org.springframework.osgi.samples.simpleservice)
ss

Framework is launched.

id	State       Bundle
0	ACTIVE      org.eclipse.osgi_3.3.1.R33x_v20070828
1	ACTIVE      org.springframework.osgi.spring-osgi-annotation_1.0.0.m3
2	ACTIVE      org.springframework.osgi.spring-osgi-io_1.0.0.m3
4	ACTIVE      org.springframework.osgi.spring-osgi-extender_1.0.0.m3
5	ACTIVE      org.springframework.osgi.spring-osgi-mock_1.0.0.m3
6	ACTIVE      org.springframework.osgi.spring-osgi-core_1.0.0.m3
15	ACTIVE      spring-context_2.1.0.m4
16	ACTIVE      spring-beans_2.1.0.m4
17	ACTIVE      org.springframework.osgi.aopalliance.osgi_1.0.0.SNAPSHOT
18	ACTIVE      spring-aop_2.1.0.m4
21	ACTIVE      jcl104.over.slf4j_1.4.3
22	ACTIVE      slf4j.api_1.4.3
25	ACTIVE      slf4j.log4j12_1.4.3
32	ACTIVE      org.springframework.osgi.samples.simpleservice_1.0.0
33	ACTIVE      org.springframework.osgi.log4j.osgi_1.2.13
34	ACTIVE      spring-core_2.1.0.m4

osgi> bundle 32
initial@reference:file:../../develop/spring-dm/Simple Service Sample bundle/ [32]
  Id=32, Status=ACTIVE      Data Root=D:\develop\spring-dm\.metadata\.plugins\org.eclipse.pde.core\Spring-DM\org.eclipse.osgi\bundles\32\data
  Registered Services
    {org.springframework.osgi.samples.simpleservice.MyService}={org.springframework.osgi.beanname=simpleService, Bundle-SymbolicName=org.springframework.osgi.samples.simpleservice, Bundle-Version=1.0, service.id=23}
    {org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext, org.springframework.osgi.internal.context.support.AbstractDelegatedExecutionApplicationContext, org.springframework.osgi.internal.context.DelegatedExecutionOsgiBundleApplicationContext, org.springframework.osgi.context.ConfigurableOsgiBundleApplicationContext, org.springframework.context.ConfigurableApplicationContext, org.springframework.context.ApplicationContext, org.springframework.context.Lifecycle, org.springframework.beans.factory.ListableBeanFactory, org.springframework.beans.factory.HierarchicalBeanFactory, org.springframework.context.MessageSource, org.springframework.context.ApplicationEventPublisher, org.springframework.core.io.support.ResourcePatternResolver, org.springframework.beans.factory.BeanFactory, org.springframework.core.io.ResourceLoader, org.springframework.osgi.context.support.AbstractOsgiBundleApplicationContext, org.springframework.context.support.AbstractRefreshableApplicationContext, org.springframework.context.support.AbstractApplicationContext, org.springframework.beans.factory.DisposableBean, org.springframework.core.io.DefaultResourceLoader}={org.springframework.context.service.name=org.springframework.osgi.samples.simpleservice, service.id=24}
  Services in use:
    {org.springframework.beans.factory.xml.NamespaceHandlerResolver}={service.id=21}
    {org.xml.sax.EntityResolver}={service.id=22}
  Exported packages
    org.springframework.osgi.samples.simpleservice; version="0.0.0"[exported]
  Imported packages
    org.apache.log4j; version="0.0.0"<initial@reference:file:../../develop/libs/osgi-bundles/log4j.osgi-1.2.13-SNAPSHOT.jar/ [33]>
    org.springframework.beans.factory; version="2.1.0.m4"<initial@reference:file:../../develop/libs/osgi-bundles/spring-beans-2.1-m4.jar/ [16]>
  No fragment bundles
  Named class space
    org.springframework.osgi.samples.simpleservice; bundle-version="1.0.0"[provided]
  No required bundles

osgi> 

Weblinks

Persönliche Werkzeuge