Similar problem here.
A boiled down version of our situation is provided. The actual implementation uses dozens of repositories that follow a similar pattern.
Consider: There exists a domain project containing POJOs and repos. There exists a separate web service project with extended versions of the repositories that just overwrite repo interfaces annotations to point at different database instances.
First consider the following interfaces:
Code:
package com.foo.bar.domain.repositories;
@Repository("domainObjRepository")
public interface DomainObjRepository extends MongoRepository<DomainObj, String> {
/* queries go here */
}
and then the specialized interface which is intended to point at production
Code:
package com.foo.bar.ws.repositories;
@Repository("domainObjProdRepository")
public interface DomainObjProdRepository extends DomainObjRepository {
}
Finally, the app-config.xml
Code:
<mongo:mongo id="stagingMongo" replica-set="${staging}"/>
<mongo:mongo id="productionMongo" replica-set="${production}" />
<mongo:db-factory id="stagingDBFactory" dbname="foobar" mongo-ref="stagingMongo"/>
<mongo:db-factory id="productionDBFactory" dbname="foobar" mongo-ref="productionMongo"/>
<bean id="stagingMongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg ref="stagingDBFactory"/>
</bean>
<bean id="productionMongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg ref="productionDBFactory"/>
</bean>
<mongo:repositories base-package="com.foo.bar.domain.repositories" >
<mongo:repository id="domainObjRepository" mongo-template-ref="stagingMongoTemplate"/>
</mongo:repositories>
<mongo:repositories base-package="com.foo.bar.ws.repositories" >
<mongo:repository id="domainObjProdRepository" mongo-template-ref="productionMongoTemplate"/>
</mongo:repositories>
<jaxrs:server id="restContainer" address="/" docLocation="docs">
<jaxrs:serviceBeans>
<!-- Staging -->
<bean id="serviceStaging" class="com.foo.bar.ws.services.DomainObjService">
<constructor-arg><ref bean="stagingRepo"/></constructor-arg>
</bean>
<!-- Production -->
<bean id="serviceProduction" class="com.foo.bar.ws.services.DomainObjService">
<constructor-arg><ref bean="productionRepo"/></constructor-arg>
</bean>
</jaxrs:serviceBeans>
</jaxrs:server>
The above configuration and interfaces allow the instancing of two of the same type of service with accept an injected Repository of type DomainObjRepository. One service is used for staging, the other for production.
When trying to upgrade to 1.1.0, this configuration isn't possible, as the repositories element no longer accepts a sequence of repository elements.
My alternative, so far as I can tell, is to create implementations of each repository, and manually instantiate them in the web service.
I'd much prefer to have Repository Sequence back, as that's just way more extra code.
Are there other solutions that I haven't considered? Recommendations, best practices, etc?
Regards,
KG