I am working on creating a library built on top of spring-data so that it would be able to dynamically generate Spring Data repositories. I was hoping to create a generic wrapper of this process that operates on the Spring Data abstraction.
This way depending on what dependency is added to the classpath example: spring-data-jpa
or spring-data-mongodb
I would be able to generate repositories and inject them into my spring context.
I was having trouble finding good documentation on how to go about doing this. Any ideas?
Spring provides a
@Conditional
annotation for controlling which beans/configurations are picked up depending on classpath ( similar with thespring-boot
autoconfiguration ).You could define two configuration classes which are picked up by spring based on your classpath. For example:
Configuration for JPA present on classpath could look something like.
Configuration for MongoDB:
All you need to do from this point forward is to use both configuration classes in your module and let spring do it's magic