0

I have been working in a application with Spring webflux and reactive mongo DB. in there i used mongo DB atlas as the database and it worked fine.

Recently i had to introduce mongo custom conversion to handle the Zoned Date Time objects.

@Configuration
public class MongoReactiveConfiguration extends AbstractReactiveMongoConfiguration{

    @Override
    public MongoCustomConversions customConversions() {
        ZonedDateTimeReadConverter zonedDateTimeReadConverter = new ZonedDateTimeReadConverter();
        ZonedDateTimeWriteConverter zonedDateTimeWriteConverter = new ZonedDateTimeWriteConverter();
        
        List<Converter<?, ?>> converterList = new ArrayList<>();
        converterList.add(zonedDateTimeReadConverter);
        converterList.add(zonedDateTimeWriteConverter);
        
        return new MongoCustomConversions(converterList);
    }
    

    @Override
    protected String getDatabaseName() {
        // TODO Auto-generated method stub
        return "stlDB";
    }
    
}

HoOwever now i no longer can connect to mongo db atlas, it ignores the proeprty spring.data.mongodb.uri and tries to connect local server with default configuration.

i tried

@EnableAutoConfiguration(exclude={MongoReactiveAutoConfiguration.class})

but then it ignored the above conversions as well. Is there any other configurations to override in AbstractReactiveMongoConfiguration to ignore the default server IP and port?

M. Deinum
  • 115,695
  • 22
  • 220
  • 224
keth
  • 793
  • 2
  • 11
  • 36
  • 2
    If you provide your own mongo configuration (like you did) Spring Boot will back off from configuring it. So yes adding this will let Spring Boot ignore the configuration. Instead adding an `@Configuration` containing an `@Bean` for the `MongoCustomConversion` might do the trick. – M. Deinum Apr 06 '21 at 07:23

1 Answers1

1

I had the same issue and could not find a solution other than configuring converters differently, without extending AbstractReactiveMongoConfiguration:

@Configuration
public class MongoAlternativeConfiguration {

    @Bean
    public MongoCustomConversions mongoCustomConversions() {

        return new MongoCustomConversions(
            Arrays.asList(
                    new ZonedDateTimeReadConverter(),
                    new ZonedDateTimeWriteConverter()));
    }
}