5

I work on a project which was extending SimpleMongoFactory to enable multi tenancy

public class MultiTenantMongoFactory extends SimpleMongoDbFactory {

After migrating from Spring boot 2.1.10 to 2.2.1, we tried to fix deprecation warning by using recommended class

SimpleMongoClientDbFactory

Compilation and application runs fine, but integration tests are broken.

My analysis is that autoconfiguration class EmbeddedMongoAutoConfiguration code :

@ConditionalOnClass({ MongoClient.class, MongoClientFactoryBean.class })
static class EmbeddedMongoClientDependsOnBeanFactoryPostProcessor
        extends MongoClientDependsOnBeanFactoryPostProcessor {

    EmbeddedMongoClientDependsOnBeanFactoryPostProcessor() {
        super(MongodExecutable.class);
    }

}

Which will call :

super(MongoClient.class, MongoClientFactoryBean.class, dependsOn);

Work only with deprecated com.mongodb.MongoClient and not recommended com.mongodb.client.MongoClient

Isn't that an issue that EmbeddedMongoAutoConfiguration may be compatible with recommended class.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Zejuho
  • 51
  • 1
  • 2
  • The authors of the MongoDB Java driver have implemented an upgraded client stack (but left the original also) which includes many new components with different namespaces but similar names. This has cause a great deal of confusion about what is the proper component to use. Further they did not deprecate every component in the old chain. This change occurred between the 2.X and 3.X branches of the Java driver. See https://stackoverflow.com/questions/29364787/mongocollection-versus-dbcollection-java for more details. – barrypicker Dec 11 '19 at 18:29
  • I have found it helpful to fully qualify my objects by their full namespace instead of using import statements. This helps me keep track of the old vs. new stuff in the driver. – barrypicker Dec 11 '19 at 18:30
  • Thanks for your replies, but i'm not sure it concerns my pb. I improve my analisys. We were using Spring class new MongoClientFactory(mongoProperties, env).createMongoClient(null) which in fact detect we are in test environment from an property set in spring environment by EmbeddedMongoAutoConfiguration class. There is no class in Spring to do the same for client.MongoClient, so i suspect srping to not offer full support – Zejuho Dec 13 '19 at 16:29
  • @Zejuho were you able to fix this issue ? – Karthikeyan May 06 '20 at 07:16
  • 1
    @Karthikeyan, last time i worked on the project, we revert to deprecated MongoClient to be able to use EmbeddedMongoAutoConfiguration. I'm pretty sure we follow spring boot release, i'll check about the current situation this week on latest spring boot 2.2. – Zejuho May 10 '20 at 21:08

1 Answers1

-1

Try the new API for mongoDB: SimpleMongoClientDatabaseFactory

mynameiszx
  • 21
  • 1