Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Note: The sample project can be downloaded, see the resources section.

...

Code Block
xml
xml
titledemo-service-bundle-contxt-osgi.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:osgi="http://www.springframework.org/schema/osgi"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
	http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/osgi
    http://www.springframework.org/schema/osgi/spring-osgi.xsd">

	<!--
		definitions using elements of the osgi namespace can be included in
		this file. There is no requirement to keep these definitions in a
		separate file if you do not want to. The rationale for keeping these
		definitions separate is to facilitate integration testing of the
		bundle outside of an OSGi container
	-->

	<osgi:service ref="transformService">
		<osgi:interfaces>
			<value>demo.service.TransformService</value>
		</osgi:interfaces>
	</osgi:service>

</beans>

The xml tag osgi:service will help to register our OSGI service top of the OSGI server and will publish the interfaces as available for another bundles who would like to use them

Remark: for more information about Spring Dynamic Modules and configuration, I recommend to read its documentation

Tip
titleSpring configuration files

Two XML files have been created to work with Spring beans and Spring OSGI beans separately (as proposed by spring - section D.1 Generated Project Features at-a-glance) but you can also merge the content in one file.

...

This command can be launched from Eclipse (if you have integrated maven within Eclipse (eclipse maven plugin)) or a Unix/Dos prompt in the folder where your pom.xml file is located:

Code Block
mvn packageorg.ops4j:maven-pax-plugin:compile

If this command does not report any error, then a 'MANIFEST.MF' file containing the following information is created in the folder 'META-INF' and
a demo.service-bundle-0.1.0.jar jar is created in the target folder:

...