You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/asciidoc/reference/gridfs.adoc
+5-8
Original file line number
Diff line number
Diff line change
@@ -3,9 +3,10 @@
3
3
4
4
MongoDB supports storing binary files inside its filesystem, GridFS. Spring Data MongoDB provides a `GridFsOperations` interface as well as the corresponding implementation, `GridFsTemplate`, to let you interact with the filesystem. You can set up a `GridFsTemplate` instance by handing it a `MongoDatabaseFactory` as well as a `MongoConverter`, as the following example shows:
5
5
6
-
.JavaConfig setup for a GridFsTemplate
6
+
7
7
====
8
-
[source,java]
8
+
.Java
9
+
[source,java,role="primary"]
9
10
----
10
11
class GridFsConfiguration extends AbstractMongoClientConfiguration {
11
12
@@ -17,13 +18,9 @@ class GridFsConfiguration extends AbstractMongoClientConfiguration {
Copy file name to clipboardExpand all lines: src/main/asciidoc/reference/mapping.adoc
+18-20
Original file line number
Diff line number
Diff line change
@@ -266,11 +266,11 @@ calling `get()` before the actual conversion
266
266
267
267
Unless explicitly configured, an instance of `MappingMongoConverter` is created by default when you create a `MongoTemplate`. You can create your own instance of the `MappingMongoConverter`. Doing so lets you dictate where in the classpath your domain classes can be found, so that Spring Data MongoDB can extract metadata and construct indexes. Also, by creating your own instance, you can register Spring converters to map specific classes to and from the database.
268
268
269
-
You can configure the `MappingMongoConverter` as well as `com.mongodb.client.MongoClient` and MongoTemplate by using either Java-based or XML-based metadata. The following example uses Spring's Java-based configuration:
269
+
You can configure the `MappingMongoConverter` as well as `com.mongodb.client.MongoClient` and MongoTemplate by using either Java-based or XML-based metadata. The following example shows the configuration:
270
270
271
-
.@Configuration class to configure MongoDB mapping support
272
271
====
273
-
[source,java]
272
+
.Java
273
+
[source,java,role="primary"]
274
274
----
275
275
@Configuration
276
276
public class MongoConfig extends AbstractMongoClientConfiguration {
@@ -299,24 +299,11 @@ public class MongoConfig extends AbstractMongoClientConfiguration {
299
299
return new LoggingEventListener<MongoMappingEvent>();
300
300
}
301
301
}
302
-
----
303
-
<1> The mapping base package defines the root path used to scan for entities used to pre initialize the `MappingContext`. By default the configuration classes package is used.
304
-
<2> Configure additional custom converters for specific domain types that replace the default mapping procedure for those types with your custom implementation.
305
-
====
306
-
307
-
`AbstractMongoClientConfiguration` requires you to implement methods that define a `com.mongodb.client.MongoClient` as well as provide a database name. `AbstractMongoClientConfiguration` also has a method named `getMappingBasePackage(…)` that you can override to tell the converter where to scan for classes annotated with the `@Document` annotation.
308
-
309
-
You can add additional converters to the converter by overriding the `customConversionsConfiguration` method.
310
-
MongoDB's native JSR-310 support can be enabled through `MongoConverterConfigurationAdapter.useNativeDriverJavaTimeCodecs()`.
311
-
Also shown in the preceding example is a `LoggingEventListener`, which logs `MongoMappingEvent` instances that are posted onto Spring's `ApplicationContextEvent` infrastructure.
312
-
313
-
NOTE: `AbstractMongoClientConfiguration` creates a `MongoTemplate` instance and registers it with the container under the name `mongoTemplate`.
314
302
315
-
Spring's MongoDB namespace lets you enable mapping functionality in XML, as the following example shows:
@@ -353,8 +340,19 @@ Spring's MongoDB namespace lets you enable mapping functionality in XML, as the
353
340
354
341
</beans>
355
342
----
343
+
<1> The mapping base package defines the root path used to scan for entities used to pre initialize the `MappingContext`. By default the configuration classes package is used.
344
+
<2> Configure additional custom converters for specific domain types that replace the default mapping procedure for those types with your custom implementation.
356
345
====
357
346
347
+
`AbstractMongoClientConfiguration` requires you to implement methods that define a `com.mongodb.client.MongoClient` as well as provide a database name. `AbstractMongoClientConfiguration` also has a method named `getMappingBasePackage(…)` that you can override to tell the converter where to scan for classes annotated with the `@Document` annotation.
348
+
349
+
You can add additional converters to the converter by overriding the `customConversionsConfiguration` method.
350
+
MongoDB's native JSR-310 support can be enabled through `MongoConverterConfigurationAdapter.useNativeDriverJavaTimeCodecs()`.
351
+
Also shown in the preceding example is a `LoggingEventListener`, which logs `MongoMappingEvent` instances that are posted onto Spring's `ApplicationContextEvent` infrastructure.
352
+
353
+
NOTE: `AbstractMongoClientConfiguration` creates a `MongoTemplate` instance and registers it with the container under the name `mongoTemplate`.
354
+
355
+
358
356
The `base-package` property tells it where to scan for classes annotated with the `@org.springframework.data.mongodb.core.mapping.Document` annotation.
359
357
360
358
[[mapping-usage]]
@@ -607,7 +605,7 @@ The mapping subsystem allows the customization of the object construction by ann
607
605
608
606
* If a parameter is annotated with the `@Value` annotation, the given expression is evaluated and the result is used as the parameter value.
609
607
* If the Java type has a property whose name matches the given field of the input document, then it's property information is used to select the appropriate constructor parameter to pass the input field value to. This works only if the parameter name information is present in the java `.class` files which can be achieved by compiling the source with debug information or using the new `-parameters` command-line switch for javac in Java 8.
610
-
* Otherwise a `MappingException` will be thrown indicating that the given constructor parameter could not be bound.
608
+
* Otherwise, a `MappingException` will be thrown indicating that the given constructor parameter could not be bound.
Copy file name to clipboardExpand all lines: src/main/asciidoc/reference/mongo-auditing.adoc
+7-10
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,11 @@
1
1
[[mongo.auditing]]
2
2
== General Auditing Configuration for MongoDB
3
3
4
-
Since Spring Data MongoDB 1.4, auditing can be enabled by annotating a configuration class with the `@EnableMongoAuditing` annotation, as the followign example shows:
4
+
Since Spring Data MongoDB 1.4, auditing can be enabled by annotating a configuration class with the `@EnableMongoAuditing` annotation, as the following example shows:
5
5
6
-
.Activating auditing using JavaConfig
7
6
====
8
-
[source,java]
7
+
.Java
8
+
[source,java,role="primary"]
9
9
----
10
10
@Configuration
11
11
@EnableMongoAuditing
@@ -17,19 +17,16 @@ class Config {
17
17
}
18
18
}
19
19
----
20
-
====
21
-
If you expose a bean of type `AuditorAware` to the `ApplicationContext`, the auditing infrastructure picks it up automatically and uses it to determine the current user to be set on domain types. If you have multiple implementations registered in the `ApplicationContext`, you can select the one to be used by explicitly setting the `auditorAwareRef` attribute of `@EnableMongoAuditing`.
22
-
23
-
To activate auditing functionality via XML, add the Spring Data Mongo `auditing` namespace element to your configuration, as the following example shows:
If you expose a bean of type `AuditorAware` to the `ApplicationContext`, the auditing infrastructure picks it up automatically and uses it to determine the current user to be set on domain types. If you have multiple implementations registered in the `ApplicationContext`, you can select the one to be used by explicitly setting the `auditorAwareRef` attribute of `@EnableMongoAuditing`.
29
+
33
30
To enable auditing, leveraging a reactive programming model, use the `@EnableReactiveMongoAuditing` annotation. +
34
31
If you expose a bean of type `ReactiveAuditorAware` to the `ApplicationContext`, the auditing infrastructure picks it up automatically and uses it to determine the current user to be set on domain types. If you have multiple implementations registered in the `ApplicationContext`, you can select the one to be used by explicitly setting the `auditorAwareRef` attribute of `@EnableReactiveMongoAuditing`.
0 commit comments