Skip to content

Instantly share code, notes, and snippets.

@rrajendran
Last active March 20, 2021 01:22
Show Gist options
  • Save rrajendran/5789545 to your computer and use it in GitHub Desktop.
Save rrajendran/5789545 to your computer and use it in GitHub Desktop.
Spring osgi service exported and imported by Blueprint. Basically if you want to share spring services with blueprint, this is the work around which worked from me.
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/blueprint"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<reference id="helloBean" interface="com.osgi.HelloWorldInterface"/>
<bean id="sageMasterStockService" class="com.osgi.blueprint.impl.HelloWorldService">
<property name="helloBean" ref="helloBean"/>
</bean>
<camelContext id="blueprintContext" trace="false" xmlns="http://camel.apache.org/schema/blueprint">
<route id="timerToLog">
<from uri="timer:foo?period=5000"/>
<bean method="hello" ref="helloBean" />
<log message="The message contains ${body}"/>
<to uri="mock:result"/>
</route>
</camelContext>
</blueprint>
<features>
<feature name="jpa-hibernate" version="${project.version}">
<bundle>mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.java-persistence-api-1.1.1/2.0.0.redhat-60024</bundle>
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-collections/3.2.1_1</bundle>
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-pool/1.5.4_2</bundle>
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-dbcp/1.4_3</bundle>
<!-- <bundle>mvn:org.springframework/spring-jdbc/3.1.3.RELEASE</bundle> -->
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.dom4j/1.6.1_2</bundle>
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.antlr/2.7.7_5</bundle>
<bundle>mvn:org.objectweb.asm/com.springsource.org.objectweb.asm/1.5.3</bundle>
<bundle>mvn:net.sourceforge.cglib/com.springsource.net.sf.cglib/2.2.0</bundle>
<bundle>mvn:org.jboss.javassist/com.springsource.javassist/3.9.0.GA</bundle>
<bundle>mvn:org.hibernate/com.springsource.org.hibernate.annotations.common/3.3.0.ga</bundle>
<bundle>mvn:org.hibernate/com.springsource.org.hibernate.annotations/3.4.0.GA</bundle>
<bundle>mvn:org.hibernate/com.springsource.org.hibernate.ejb/3.4.0.GA</bundle>
<bundle>mvn:org.hibernate/com.springsource.org.hibernate/3.3.2.GA</bundle>
<!-- <bundle>mvn:org.springframework/spring-orm/3.1.3.RELEASE</bundle> -->
</feature>
<feature name="spring-dependencies" version="3.1.3.RELEASE">
<bundle>mvn:org.springframework/spring-orm/3.1.3.RELEASE</bundle>
<bundle>mvn:org.springframework/spring-oxm/3.1.3.RELEASE</bundle>
<bundle>mvn:org.springframework/spring-tx/3.1.3.RELEASE</bundle>
<bundle>mvn:org.springframework/spring-jdbc/3.1.3.RELEASE</bundle>
</feature>
<feature name="mysql-connector-java" version="5.1.24">
<bundle>mvn:mysql/mysql-connector-java/5.1.24</bundle>
</feature>
<feature name="jpa-dependencies" version="${project.version}">
<bundle>mvn:org.apache.openjpa/openjpa/2.2.1</bundle>
<bundle>mvn:org.apache.geronimo.specs/geronimo-jta_1.1_spec/1.1.1</bundle>
<bundle>mvn:org.apache.geronimo.specs/geronimo-jpa_2.0_spec/1.1</bundle>
<bundle>mvn:org.apache.aries/org.apache.aries.util/1.0.1.redhat-60024</bundle>
<bundle>mvn:org.apache.aries.jpa/org.apache.aries.jpa.api/1.0.1.redhat-60024</bundle>
<bundle>mvn:org.apache.aries.jpa/org.apache.aries.jpa.blueprint.aries/1.0.1.redhat-60024</bundle>
<bundle>mvn:org.apache.aries.jpa/org.apache.aries.jpa.container/1.0.1.redhat-60024</bundle>
<bundle>mvn:org.apache.aries.jpa/org.apache.aries.jpa.container.context/1.0.1.redhat-60024</bundle>
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.serp/1.14.1_1</bundle>
</feature>
<feature name="joda-time" version="2.2">
<bundle>mvn:joda-time/joda-time/2.2</bundle>
</feature>
<feature name="esb-database-dependencies" version="${project.version}">
<feature version="${project.version}">jpa-dependencies</feature>
<feature version="${project.version}">jpa-hibernate</feature>
<feature version="3.1.3.RELEASE">spring-dependencies</feature>
<feature version="5.1.24">mysql-connector-java</feature>
<feature version="2.2">joda-time</feature>
</feature>
<feature name="esb-database" version="${project.version}">
<bundle>mvn:${project.groupId}/fuse-database/${project.version}</bundle>
</feature>
</features>
<!-- to generate the MANIFEST-FILE of the bundle -->
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Private-Package>com.osgi.*</Private-Package>
<Export-Package>com.osgi.*</Export-Package>
<DynamicImport-Package>*</DynamicImport-Package>
<Import-Package>
org.springframework*;version="[2.5,4.0)",
javax.persistence*;version="[1.1.0,2.1.0)",
javax.persistence.criteria;version="[1.1.0,2.1.0)",
javax.sql,
*
</Import-Package>
<Export-Service>com.osgi.HelloWorldInterface</Export-Service>
</instructions>
</configuration>
</plugin>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:osgix="http://www.springframework.org/schema/osgi-compendium"
xmlns:camel="http://camel.apache.org/schema/spring" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://www.springframework.org/schema/osgi" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/osgi-compendium
http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd">
<context:annotation-config />
<context:component-scan base-package="com.osgi" />
<tx:annotation-driven transaction-manager="txManager" />
<!-- Property place holder will be referred by properties exposed by blueprint -->
<context:property-placeholder properties-ref="databaseProperties" />
<!-- enables interpretation of the @PersistenceUnit/@PersistenceContext
annotations providing convenient access to EntityManagerFactory/EntityManager -->
<bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="reportIncident" />
<property name="jpaVendorAdapter" ref="jpaAdapterMYSQL" />
<property name="dataSource" ref="dataSource" />
</bean>
<!-- OpenJPA MySQL adapter -->
<bean id="jpaAdapterMYSQL" class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter">
<property name="databasePlatform" value="org.apache.openjpa.jdbc.sql.MySQLDictionary" />
<property name="showSql" value="true" />
</bean>
<!-- DataSource MYSQL -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${driver.class.name}" />
<property name="url" value="${url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
</bean>
<!-- TransactionManager is required -->
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="dataSource" ref="dataSource" />
</bean>
<!-- Exporting interface as osgi service, which will registered at Service Registry-->
<osgi:service ref="helloWorld" interface="com.osgi.HelloWorldInterface" />
<!-- Expose Transaction Manager -->
<osgi:service ref="txManager" interface="org.springframework.transaction.PlatformTransactionManager">
<osgi:service-properties>
<entry key="tx" value="JPA" />
</osgi:service-properties>
</osgi:service>
<!-- Exposed the blueprint properties, which will be referenced by spring property place holder -->
<osgix:cm-properties id="databaseProperties" persistent-id="com.osgi.database" >
<prop key="driver.class.name">com.mysql.jdbc.Driver</prop>
<prop key="url">jdbc:mysql://localhost:3306/flickr</prop>
<prop key="username">root</prop>
<prop key="password">welcome1</prop>
</osgix:cm-properties>
</beans>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment