Versions Compared

Key

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

...

and look at the result generated by the plugin. The Import-Package section is dry.

Now that our pom.xml is configurated configured we will modified our spring.xml files to allow our DAO service to be registered as a OSGI service. Why, because the classes of the bundle reportincident.service use this DAO class and required that this service (let's say Hibernate stuff like create SessionFactory) is instantiated during bundle osgi startup

Create the file persistence-osgi.xml in the directory src/main/resources/META-INF/spring and add the lines :

Code Block
<?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">
                      
    <osgi:service ref="incidentDAO" interface="org.apache.camel.example.reportincident.dao.IncidentDAO"/>

</beans>

The osgi:service xml tag tell to Spring Dynamic Modules to register the interface org.apache.camel.example.reportincident.dao.IncidentDAO as a service in the OSGI registry. This feature proposed by Spring will be part of the next OSGI specification R4.2 under the name of Blueprint.

Remark :

Another feature that I would like to introduce here concerns the Configuration Admin. In its simplest form, the CM can be seen as a configuration source, namely a Dictionary whose keys are always Strings. Spring DM can expose entries in the CM as a Properties object, through the cm-properties element. A minimal declaration looks as follows:

Code Block

The configuration above, exposes the properties available in the CM under data.source.office.1 entry as a bean named ds.cfg. Moreover, we will create 'for the deployment' a file 'org.apache.camel.example.reportincident.datasource.cfg' that the OSGI registry service will use to instantiate the preporties.

Remarks :

  • If the file is not found, the properties declared in the spring xml file will be used.
  • In our example, we have only defined properties for the driver, username and {{password }} but you can extend the list of values with by example Hibernate parameters like hibernate.show_sql, hibernate.format_sql, ...

3) reportincident.service

Routing/Mediation service

...