Skip to content

Commit 38b7a72

Browse files
hzpzmp911de
authored andcommitted
DATAMONGO-1270 - Update documentation to reflect deprecation of MongoFactoryBean.
Original pull request: #315.
1 parent bccd9e2 commit 38b7a72

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/main/asciidoc/reference/mongodb.adoc

+5-5
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,11 @@ public class AppConfig {
195195

196196
This approach allows you to use the standard `com.mongodb.Mongo` API that you may already be used to using but also pollutes the code with the UnknownHostException checked exception. The use of the checked exception is not desirable as Java based bean metadata uses methods as a means to set object dependencies, making the calling code cluttered.
197197

198-
An alternative is to register an instance of `com.mongodb.Mongo` instance with the container using Spring's` MongoFactoryBean`. As compared to instantiating a `com.mongodb.Mongo` instance directly, the FactoryBean approach does not throw a checked exception and has the added advantage of also providing the container with an ExceptionTranslator implementation that translates MongoDB exceptions to exceptions in Spring's portable `DataAccessException` hierarchy for data access classes annoated with the `@Repository` annotation. This hierarchy and use of `@Repository` is described in http://docs.spring.io/spring/docs/current/spring-framework-reference/html/dao.html[Spring's DAO support features].
198+
An alternative is to register an instance of `com.mongodb.Mongo` instance with the container using Spring's `MongoClientFactoryBean`. As compared to instantiating a `com.mongodb.Mongo` instance directly, the FactoryBean approach does not throw a checked exception and has the added advantage of also providing the container with an ExceptionTranslator implementation that translates MongoDB exceptions to exceptions in Spring's portable `DataAccessException` hierarchy for data access classes annoated with the `@Repository` annotation. This hierarchy and use of `@Repository` is described in http://docs.spring.io/spring/docs/current/spring-framework-reference/html/dao.html[Spring's DAO support features].
199199

200200
An example of a Java based bean metadata that supports exception translation on `@Repository` annotated classes is shown below:
201201

202-
.Registering a com.mongodb.Mongo object using Spring's MongoFactoryBean and enabling Spring's exception translation support
202+
.Registering a com.mongodb.Mongo object using Spring's MongoClientFactoryBean and enabling Spring's exception translation support
203203
====
204204
[source,java]
205205
----
@@ -209,16 +209,16 @@ public class AppConfig {
209209
/*
210210
* Factory bean that creates the com.mongodb.Mongo instance
211211
*/
212-
public @Bean MongoFactoryBean mongo() {
213-
MongoFactoryBean mongo = new MongoFactoryBean();
212+
public @Bean MongoClientFactoryBean mongo() {
213+
MongoClientFactoryBean mongo = new MongoClientFactoryBean();
214214
mongo.setHost("localhost");
215215
return mongo;
216216
}
217217
}
218218
----
219219
====
220220

221-
To access the `com.mongodb.Mongo` object created by the `MongoFactoryBean` in other `@Configuration` or your own classes, use a "`private @Autowired Mongo mongo;`" field.
221+
To access the `com.mongodb.Mongo` object created by the `MongoClientFactoryBean` in other `@Configuration` or your own classes, use a "`private @Autowired Mongo mongo;`" field.
222222

223223
[[mongo.mongo-xml-config]]
224224
=== Registering a Mongo instance using XML based metadata

0 commit comments

Comments
 (0)