Sneak Preview: Using Spring Data Kay with Eclipse Virgo

Earlier this year Gemini Blueprint 3.0.0.M01 has been shipped.

“Most notably, it (Gemini Blueprint) has been upgraded to Spring 5”

The current version of Virgo recipe "Accessing Data with MongoDB” is based on Eclipse Virgo 3.7.x which ships with Spring 4.3.x.

Virgo did Update Gemini Blueprint to 3.0.0.M01. A CI build including this change is available as a sneak preview from Jenkins > Virgo > virgo-blueprint3.

Let's give it a try:

Simply changing the MongoDB driver and Spring Data versions used in the recipe from Ingalls SR13 to Kay SR8 in gradle.properties weren’t enough.

# Spring Data Kay SR8
mongoJavaDriverVersion = 3.8.0
springDataCommonsVersion = 2.0.8.RELEASE
springDataMongodbVersion = 2.0.8.RELEASE

The 2.x stream of Spring Data Core ships with the following metadata:

Implementation-Title: Spring Data Core
Automatic-Module-Name: spring.data.commons
Implementation-Version: 2.0.0.RELEASE

As you can see no OSGi metadata is present. Based on the template.mf present in the 1.x stream we enhance the bundles with bundlor 1.1.3.M01 while preparing our custom Virgo runtime.

With the OSGi bundles prepared and the applicationContext.xml updated to spring-mongo-2.0.xsd like follows:

<beans xmlns="...">
    <context:property-placeholder location="classpath:mongodb.properties" />

    <mongo:mongo-client host="${mongodb.host:localhost}" port="${mongodb.port:27017}"/>
    <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
        <constructor-arg ref="mongoClient"/>
        <constructor-arg name="databaseName" value="recipe"/>
    </bean>

    <mongo:repositories base-package="org.eclipse.virgo.samples.recipe.data.mongodb" />

    <context:component-scan base-package="org.eclipse.virgo.samples.recipe.data.mongodb" />
</beans>

All reconditioned puzzle pieces are back in place. Dropping the sample bundle into the pickup folder of Virgo results in the expected console output:

Customers found with findAll(): 
------------------------------- 
Customer[id=5b3b83195adf962e834ac5d2, firstName='Alice', lastName='Smith']
Customer[id=5b3b83195adf962e834ac5d3, firstName='Bob', lastName='Smith']

Customer found with findByFirstName('Alice'):
-------------------------------- 
Customer[id=5b3b83195adf962e834ac5d2, firstName='Alice', lastName='Smith']
Customers found with findByLastName('Smith'): 
-------------------------------- 
Customer[id=5b3b83195adf962e834ac5d2, firstName='Alice', lastName='Smith']
Customer[id=5b3b83195adf962e834ac5d3, firstName='Bob', lastName='Smith']

Looks good.

The complete sneak preview of the updated recipe is available here.

In case you want to try it yourself please grab the companion code available on branch feature/spring_data_kay of the Virgo samples https://github.com/eclipse/virgo.samples/.

The Virgo team highly appreciates your feedback…