Merge branch '1.5.x'
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
= Spring Boot Reference Guide
|
||||
Phillip Webb; Dave Syer; Josh Long; Stéphane Nicoll; Rob Winch; Andy Wilkinson; Marcel Overdijk; Christian Dupuis; Sébastien Deleuze
|
||||
Phillip Webb; Dave Syer; Josh Long; Stéphane Nicoll; Rob Winch; Andy Wilkinson; Marcel Overdijk; Christian Dupuis; Sébastien Deleuze; Michael Simons
|
||||
:doctype: book
|
||||
:toc:
|
||||
:toclevels: 4
|
||||
|
||||
@@ -3435,6 +3435,9 @@ property. To use a randomly allocated free port use a value of zero. The `MongoC
|
||||
created by `MongoAutoConfiguration` will be automatically configured to use the randomly
|
||||
allocated port.
|
||||
|
||||
NOTE: If you do not configure a custom port, the embedded support will use a random port
|
||||
by default (rather than 27017).
|
||||
|
||||
If you have SLF4J on the classpath, output produced by Mongo will be automatically routed
|
||||
to a logger named `org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongo`.
|
||||
|
||||
@@ -5643,6 +5646,55 @@ A list of the auto-configuration that is enabled by `@JdbcTest` can be
|
||||
|
||||
|
||||
|
||||
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-mongo-test]]
|
||||
==== Auto-configured Data MongoDB tests
|
||||
`@DataMongoTest` can be used if you want to test MongoDB applications. By default, it will
|
||||
configure an in-memory embedded MongoDB (if available), configure a `MongoTemplate`, scan
|
||||
for `@Document` classes and configure Spring Data MongoDB repositories. Regular
|
||||
`@Component` beans will not be loaded into the `ApplicationContext`:
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@DataMongoTest
|
||||
public class ExampleDataMongoTests {
|
||||
|
||||
@Autowired
|
||||
private MongoTemplate mongoTemplate;
|
||||
|
||||
//
|
||||
}
|
||||
----
|
||||
|
||||
In-memory embedded MongoDB generally works well for tests since it is fast and doesn't
|
||||
require any developer installation. If, however, you prefer to run tests against a real
|
||||
MongoDB server you should exclude the embedded mongodb auto-configuration:
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration;
|
||||
import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@DataMongoTest(excludeAutoConfiguration = EmbeddedMongoAutoConfiguration.class)
|
||||
public class ExampleDataMongoNonEmbeddedTests {
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
A list of the auto-configuration that is enabled by `@DataMongoTest` can be
|
||||
<<appendix-test-auto-configuration#test-auto-configuration,found in the appendix>>.
|
||||
|
||||
|
||||
|
||||
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-rest-client]]
|
||||
==== Auto-configured REST clients
|
||||
The `@RestClientTest` annotation can be used if you want to test REST clients. By default
|
||||
|
||||
Reference in New Issue
Block a user