[BUG] spring.factories is not published with final azure-spring-data-cosmos artifact #17651
Closed
3 tasks done
Labels
azure-spring
All azure-spring related issues
azure-spring-cosmos
Spring cosmos related issues.
Client
This issue points to a problem in the data-plane of the library.
customer-reported
Issues that are reported by GitHub users external to the Azure organization.
question
The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Describe the bug
The spring.factories file that contains....
org.springframework.data.repository.core.support.RepositoryFactorySupport=com.azure.spring.data.cosmos.repository.support.CosmosRepositoryFactory
is not getting published with the azure-spring-data-cosmos artifact.
The main side effect of this that I have noticed is that the library does not work alongside other spring-data modules. In my case I was using it along side spring-data-jpa with a relational database. Not having this in place causes bean instantiation exceptions on startup. Spring has code internally that detects if multiple spring data modules are registered and it does this by seeing how many classes that extend RepositoryFactorySupport it has in the factories loader (CosmosRepositoryFactory extends RepositoryFactorySupport). Specifically this code...
Without the spring.factories file in place, the above code does not detect CosmosRepositoryFactory and thinks spring-data-jpa is the only module registered. This sends spring down a different code path that only allows a single RepositoryFactoryBean instance to be instantiated instead of a RepositoryFactoryBean for each type of spring-data-module.
Exception or Stack Trace
The error that is raised when you try to use azure-spring-data-cosmos alongside another spring data module will look like this (in this case its used alongside spring-data-jpa)...
Cannot register bean definition [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]
preceded by....
There is already [Root bean: class [com.azure.spring.data.cosmos.repository.support.CosmosRepositoryFactoryBean]
If the spring.factories file was in the artifact, spring would detect that multiple spring-data modules are registered and it would allow both of these beans to exist.
To Reproduce
Use azure-spring-data-cosmos alongside one other spring-data module like spring-data-jpa or spring-data-mongo
Expected behavior
The spring.factories file that already exists in the project here...
https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/cosmos/azure-spring-data-cosmos/src/main/resources/META-INF/spring.factories
should be published with the azure-spring-data-cosmos artifact
Workaround
Add the spring.factories file to your own project
Setup (please complete the following information):
Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
The text was updated successfully, but these errors were encountered: