Reactive MongoDB multiple database connections

Is there a way to make a multiple mongo database connection configuration with reactive mongo. Currently using the following to make a webflux back-end that needs to connect to 2 different databases:

  • Springboot: 2.3.1.RELEASE
  • Webflux (this is the important part!! not using MVC)
  • JAVA 11
  • Gradle 6.5

I tried to translate my already existing MongoDB configuration to Webflux but I get the following error:

Parameter 0 of constructor in nl.suitless.moduleservice.Services.Module.ModuleService required a bean named 'reactiveMongoTemplate' that could not be found.


Consider defining a bean named 'reactiveMongoTemplate' in your configuration.


public class MultipleMongoConfig {

    private final MultipleMongoProperties mongoProperties;

    public MultipleMongoConfig(MultipleMongoProperties mongoProperties) {
        this.mongoProperties = mongoProperties;

    @Bean(name = "primaryReactiveMongoTemplate")
    public ReactiveMongoTemplate primaryReactiveMongoTemplate() {
        return new ReactiveMongoTemplate(primaryFactory(this.mongoProperties.getPrimary()));

    @Bean(name = "secondaryReactiveMongoTemplate")
    public ReactiveMongoTemplate secondaryReactiveMongoTemplate() {
        return new ReactiveMongoTemplate (secondaryFactory(this.mongoProperties.getSecondary()));

    public SimpleReactiveMongoDatabaseFactory primaryFactory(final MongoProperties mongo) {
        MongoClient client = MongoClients.create(mongo.getUri());
        return new SimpleReactiveMongoDatabaseFactory(client, mongo.getDatabase());

    public SimpleReactiveMongoDatabaseFactory secondaryFactory(final MongoProperties mongo) {
        return new SimpleReactiveMongoDatabaseFactory(MongoClients.create(mongo.getUri()), mongo.getDatabase());
@EnableMongoRepositories(basePackages = "nl.suitless.moduleservice.Data.repositories",
        mongoTemplateRef = "primaryReactiveMongoTemplate")
public class PrimaryReactiveMongoConfig {


same for the secondaryReactiveMongoConfig.


@ConfigurationProperties(prefix = "mongodb")
public class MultipleMongoProperties {

    private MongoProperties primary;
    private MongoProperties secondary;

    public MultipleMongoProperties(){

    public MongoProperties getPrimary() {
        return primary;

    public void setPrimary(MongoProperties primary) {
        this.primary = primary;

    public MongoProperties getSecondary() {
        return secondary;

    public void setSecondary(MongoProperties secondary) {
        this.secondary = secondary;

Read more here:

Content Attribution

This content was originally published by spoilerd do at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: