spring-data-mongodb
spring-data-mongodb copied to clipboard
Enhance reference documentation and cover MongoManagedTypes
MongoManagedTypes are not mentioned in the v 4.0 release even though they where released in that version. They are needed when overriding mongoMappingContext(MongoCustomConversions customConversions, MongoManagedTypes types) which are needed for custom converters. Can you update java-doc and give an example where there is 2 or more customConverters?
Thanks for pointing out the blank spot in the reference documentation.
As per the Javadoc of the ManagedTypes interface those are:
Types managed by a Spring Data implementation. Used to predefine a set of known entities that might need processing during the initialization phase.
Basically its the initial entity set now exposed as a dedicated type which helps detect them during a potential AOT phase to run inspections required when building a GraalVM native-image.
Yes, I found the commit where the change was done: java/org/springframework/data/mongodb/config/MongoConfigurationSupport.java
Before it was mappingContext.setInitialEntitySet(getInitialEntitySet()); and now it is mappingContext.setManagedTypes(managedTypes); So my question is - how to I migrate with this change in mind - now that mongoMappingContext() takes a new argument as input? Related stackexchange question https://stackoverflow.com/questions/75996137/what-are-mongomanagedtypes-new-in-spring-data-mongodb-version-4-0
Basically its the initial entity set now exposed as a dedicated type which helps detect them during a potential AOT phase to run inspections required when building a GraalVM native-image.
How can I set them?
Can you share a complete minimal sample (something that we can unzip or git clone, build, and deploy) that shows what you're trying to achieve. I seem to lack some context form the linked SO question and the error posted there.
The attached image shows the problem - in spring-data-mongodb 4.0 the method getMappingBasePackages() which is defined with @ Override is not called anymore: https://ibb.co/ZdChJbQ The stacktrace to the left is using spring-data-mongodb 3.2 - and the stacktrace contains SecurityMongoConfig before the CGLIB spring magic, while in spring-data-mongodb 4.0- there is some CGLIB magic happening before parent classes. Is that causing overriding not to work?
Edit: The error is that after refactoring to create MonoManagedTypes in the mongoMappingContext() - our getMappingBasePages() is not called anymore.
Why do you think getMappingBasePackages is no longer called?
MongoConfigurationSupport uses getInitialEntitySet to create the MongoManagedTypes bean out of the configured base packages. As already said, please provide a complete minimal sample that reproduces the problem. Screenshots unfortunately contain way to little information to be of value.
I know getMappingBasePackages is no longer called! I see it when debugging. The default implementation of getMappingBasePackage is called instead. And that is the reason for the error. A minimal sample would just be any implementation that overrides getMappingBasePackage.
public class FooBarMongoConfig extends AbstractFooBarMongoConfig { .... @Override protected Collection<String> getMappingBasePackages() { return List.of("com.foo.bar.entity"); } }
public abstract class AbstractFooBarMongoConfig extends AbstractReactiveMongoConfiguration { ... }
Then providing the sample should not be an issue.