Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mongo Connector doesn't work with Spring Boot 2.4.1? #314

Closed
ddoubleday opened this issue Apr 6, 2021 · 7 comments
Closed

Mongo Connector doesn't work with Spring Boot 2.4.1? #314

ddoubleday opened this issue Apr 6, 2021 · 7 comments

Comments

@ddoubleday
Copy link

ddoubleday commented Apr 6, 2021

I am trying to use spring-boot-starter-cloud-connectors 2.2.12 with SB 2.4.1. I'm a little confused about what is going on because the latest listed release here is 2.0.7, but 2.2.12 is available from somewhere.

Anyway, things have been going fine up until I ran into the problem that SB 2.4.1 requires spring-data-mongodb 3.1.2, which requires Mongo driver 4.x "sync" driver, not the "legacy" driver.

I am still able to create local mongodb connections and all my tests pass, but I can't can't connect to a cloud mongo because MongoDbFactoryCreator is trying to use MongoOptions, which is only in the legacy driver.

I have a huge installed base of services that depend on Cloud Connectors, and switching to the very different cf-env is going to be a blocker for upgrade if I can't resolve this issue.

Is there any hope?

@scottfrederick
Copy link
Contributor

The most recent Spring Cloud Connectors release is 2.0.7.

The org.springframework.boot:spring-boot-starter-cloud-connectors artifact was one of the starters that are delivered with Spring Boot, not part of Spring Cloud Connectors. The spring-boot-starter-cloud-connectors artifact was removed in Spring Boot 2.3.0. There was indeed a 2.2.12 release of spring-boot-starter-cloud-connectors, but that's the last version of Boot that included that starter.

Spring Cloud Connectors was put into maintenance mode nearly 2 year ago, largely due to the fact that it was built before Spring Boot and it was very difficult to maintain compatibility with Boot as the two projects evolved. Changing Connectors to use a completely different MongoDB driver would not be a trivial change, and would require a new minor version release of Connectors (e.g. 2.1.0) because it would be backward-incompatible with previous releases. I'm afraid that's not something we are able to do after announcing the deprecation of the library so long ago.

Java CFEnv was designed to work with Boot auto-configuration instead of competing with it. In many cases it is a drop-in replacement for Connectors, but that depends on how much of the Connectors API you are using. If you have specific questions or issues with migrating I'm happy to help however I can here.

@ddoubleday
Copy link
Author

ddoubleday commented Apr 7, 2021

Thanks for the info and the offer. Could you suggest what I would do to replace this class with CFEnv? I tried to create my own extended AbstractCloudConfig and ServiceConnector so I could create MongoDatabaseFactory instead of MongoDbFactory, but the internals still direct to MongoDbFactory, so that didn't work. I think I would have to fork Cloud Connectors and change the registry.

@Profile("cloud")
public class CloudMongoDatabaseFactoryConfiguration extends AbstractCloudConfig {

    private final Environment environment;

    @Autowired
    public CloudMongoDatabaseFactoryConfiguration(Environment environment) {
        this.environment = environment;
    }

    @ConditionalOnProperty("mongodb.template.primary.serviceid")
    @Primary
    @Bean("mongodb.primary.mongoDBFactory")
    public MongoDbFactory primaryMongoDatabaseFactory() {
        String serviceId = environment.getProperty("mongodb.template.primary.serviceid");
        return connectionFactory().mongoDbFactory(serviceId);
    }


    @ConditionalOnProperty("mongodb.template.secondary.serviceid")
    @Bean("mongodb.secondary.mongoDBFactory")
    public MongoDbFactory secondaryMongoDatabaseFactory() {
        String serviceId = environment.getProperty("mongodb.template.secondary.serviceid");
        return connectionFactory().mongoDbFactory(serviceId);
    }
}

@ddoubleday
Copy link
Author

ddoubleday commented Apr 7, 2021

I think maybe I do see what I can do with CFEnv from this JDBC example:

String jdbcUrl1 = cfJdbcEnv.findJdbcServiceByName("mysqlA").getUrl();
String jdbcUrl2 = cfJdbcEnv.findJdbcServiceByName("mysqlB").getUrl();

Just get the conn properties for each service and build my own ConnectionString. I will try that.

@ddoubleday
Copy link
Author

I don't think the CFEnvProcessor for Mongo would work in my case because I have potentially two different connections.

@scottfrederick
Copy link
Contributor

Multiple connections of the same type (for example MongoDB) is a use case that neither Connectors or Spring Boot auto-configuration can handle without writing some code. This is a scenario where Java CFEnv isn't a drop-in replacement for Connectors, but hopefully it's not too much code to migrate. Let me know how its going and whether a sample of using Java CFEnv API in a scenario like this would be helpful.

@ddoubleday
Copy link
Author

ddoubleday commented Apr 24, 2021

I am gradually getting my libraries converted. Once they're all converted I'll be able to try an app, since you can't mix CFEnv and Connectors. (I have some integration test apps that are working with CFEnv.)

I am using core CFEnv instead of the Boot version because we have some special needs with multiple data sources, multiple Redis instances, etc.

I must say that CFEnv is really much easier to understand and use than Connectors. I guess that's because it is such a thin layer over CF and doesn't have to worry about Cloud-portability

@scottfrederick
Copy link
Contributor

@ddoubleday I'm going to close this issue, since there hasn't been any activity for a while. Feel free to reach out if you have any more questions or issues with your migration to Java CFEnv.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants