Commit 9b7bc690 authored by Stephane Nicoll's avatar Stephane Nicoll

Merge pull request #16467 from ayudovin

* pr/16467:
  Polish "Add auto-configuration support for ReactiveGridFsTemplate"
  Add auto-configuration support for ReactiveGridFsTemplate
parents 1a05851f e24c17d5
......@@ -29,6 +29,8 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
import org.springframework.data.mongodb.ReactiveMongoDatabaseFactory;
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
import org.springframework.data.mongodb.core.SimpleReactiveMongoDatabaseFactory;
......@@ -37,6 +39,7 @@ import org.springframework.data.mongodb.core.convert.MongoConverter;
import org.springframework.data.mongodb.core.convert.MongoCustomConversions;
import org.springframework.data.mongodb.core.convert.NoOpDbRefResolver;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
import org.springframework.data.mongodb.gridfs.ReactiveGridFsTemplate;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Spring Data's reactive mongo
......@@ -49,6 +52,7 @@ import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
* to the {@literal test} database.
*
* @author Mark Paluch
* @author Artsiom Yudovin
* @since 2.0.0
*/
@Configuration(proxyBeanMethods = false)
......@@ -85,4 +89,20 @@ public class MongoReactiveDataAutoConfiguration {
return mappingConverter;
}
@Bean
@ConditionalOnMissingBean
public DefaultDataBufferFactory dataBufferFactory() {
return new DefaultDataBufferFactory();
}
@Bean
@ConditionalOnMissingBean
public ReactiveGridFsTemplate reactiveGridFsTemplate(
ReactiveMongoDatabaseFactory reactiveMongoDbFactory,
MappingMongoConverter mappingMongoConverter,
DataBufferFactory dataBufferFactory) {
return new ReactiveGridFsTemplate(dataBufferFactory, reactiveMongoDbFactory,
mappingMongoConverter, null);
}
}
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -23,6 +23,7 @@ import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoCon
import org.springframework.boot.autoconfigure.mongo.MongoReactiveAutoConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
import org.springframework.data.mongodb.gridfs.ReactiveGridFsTemplate;
import static org.assertj.core.api.Assertions.assertThat;
......@@ -30,6 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link MongoReactiveDataAutoConfiguration}.
*
* @author Mark Paluch
* @author Artsiom Yudovin
*/
public class MongoReactiveDataAutoConfigurationTests {
......@@ -45,6 +47,12 @@ public class MongoReactiveDataAutoConfigurationTests {
.hasSingleBean(ReactiveMongoTemplate.class));
}
@Test
public void gridFsTemplateExists() {
this.contextRunner.run((context) -> assertThat(context)
.hasSingleBean(ReactiveGridFsTemplate.class));
}
@Test
public void backsOffIfMongoClientBeanIsNotPresent() {
ApplicationContextRunner runner = new ApplicationContextRunner()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment