Я пишу приложение Spring Webflux с MongoDB. Когда я удаляю все содержимое и сохраняю новое содержимое. Я вижу в журналах, что открыто 11 подключений и остается на неопределенное время, пока я не закрою приложение. Может ли кто-нибудь исправить меня, что не так с приведенным ниже кодом
@SpringBootApplication(exclude = {
MongoDataAutoConfiguration.class, MongoAutoConfiguration.class }) @EnableReactiveMongoRepositories public class Application {
private Logger log = LoggerFactory.getLogger(getClass());
@Autowired private ProductRepository productRepository;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean public void insertData() throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
List<ProductDocument> products = new ArrayList<>();
// Added some 1000 products to the list
productRepository.deleteAll().subscribe(null, null, () -> {
productRepository.saveAll(products).subscribe();
}
);
}
}
При выполнении кода выше, я вижу, есть несколько открытых соединений, которые остаются неопределенными.
2020-04-16 12:20:10.609 INFO 41444 --- [ntLoopGroup-2-5] org.mongodb.driver.connection : Opened connection [connectionId{localValue:5, serverValue:35}] to localhost:27017
2020-04-16 12:20:10.624 INFO 41444 --- [ntLoopGroup-2-6] org.mongodb.driver.connection : Opened connection [connectionId{localValue:6, serverValue:36}] to localhost:27017
2020-04-16 12:20:10.637 INFO 41444 --- [ntLoopGroup-2-4] org.mongodb.driver.connection : Opened connection [connectionId{localValue:4, serverValue:34}] to localhost:27017
2020-04-16 12:20:10.637 INFO 41444 --- [ntLoopGroup-2-8] org.mongodb.driver.connection : Opened connection [connectionId{localValue:8, serverValue:38}] to localhost:27017
2020-04-16 12:20:10.638 INFO 41444 --- [ntLoopGroup-2-7] org.mongodb.driver.connection : Opened connection [connectionId{localValue:7, serverValue:37}] to localhost:27017
2020-04-16 12:20:10.664 INFO 41444 --- [ntLoopGroup-2-9] org.mongodb.driver.connection : Opened connection [connectionId{localValue:9, serverValue:39}] to localhost:27017
2020-04-16 12:20:10.670 INFO 41444 --- [tLoopGroup-2-10] org.mongodb.driver.connection : Opened connection [connectionId{localValue:10, serverValue:40}] to localhost:27017
2020-04-16 12:20:10.676 INFO 41444 --- [tLoopGroup-2-11] org.mongodb.driver.connection : Opened connection [connectionId{localValue:11, serverValue:41}] to localhost:27017
2020-04-16 12:20:10.720 INFO 41444 --- [tLoopGroup-2-12] org.mongodb.driver.connection : Opened connection [connectionId{localValue:12, serverValue:42}] to localhost:27017
2020-04-16 12:20:10.737 INFO 41444 --- [tLoopGroup-2-13] org.mongodb.driver.connection : Opened connection [connectionId{localValue:13, serverValue:43}] to localhost:27017
2020-04-16 12:20:10.749 INFO 41444 --- [tLoopGroup-2-14] org.mongodb.driver.connection : Opened connection [connectionId{localValue:14, serverValue:44}] to localhost:27017