I am trying to understand how I can shutdown the connection to mongo while my java application runs for tesing purposes. I am trying to see how my application would behave in case mongo is unavailable. Is there any way this accomplished at the application level without touching the mongo database?. This is the class I use to create the mongo connection
@Configuration
@EnableMongoAuditing
public class MongoConfiguration {
@Autowired
private MongoProperties mongoProperties;
@Bean
public MongoClient mongo(){
ConnectionString connectionString = new ConnectionString(mongoProperties.getUri());
MongoClientSettings mongoClientSettings = MongoClientSettings.builder()
.applyConnectionString(connectionString)
.build();
return MongoClients.create(mongoClientSettings);
}
// to use @Transactional -- supporting spring data transaction support in MongoDB
@Bean
MongoTransactionManager transactionManager(MongoDbFactory dbFactory){
return new MongoTransactionManager(dbFactory);
}
@Primary
@Bean(name = "mongoTemplate")
public MongoTemplate mongoTemplate(){
return new MongoTemplate(mongo(), mongoProperties.getDatabase());
}
}