1
1
/*
2
- * Copyright 2010- 2011 the original author or authors.
2
+ * Copyright 2011-2012 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
18
18
import java .util .HashSet ;
19
19
import java .util .Set ;
20
20
21
- import com .mongodb .Mongo ;
22
21
import org .springframework .beans .factory .config .BeanDefinition ;
23
22
import org .springframework .context .annotation .Bean ;
24
23
import org .springframework .context .annotation .ClassPathScanningCandidateComponentProvider ;
35
34
import org .springframework .util .ClassUtils ;
36
35
import org .springframework .util .StringUtils ;
37
36
37
+ import com .mongodb .Mongo ;
38
+
39
+ /**
40
+ * Abstract base class to ease JavaConfig setup for Spring Data MongoDB.
41
+ *
42
+ * @author Mark Pollack
43
+ * @author Oliver Gierke
44
+ */
38
45
@ Configuration
39
46
public abstract class AbstractMongoConfiguration {
40
47
@@ -50,10 +57,11 @@ public MongoTemplate mongoTemplate() throws Exception {
50
57
51
58
@ Bean
52
59
public MongoDbFactory mongoDbFactory () throws Exception {
53
- if (getUserCredentials () == null ) {
60
+ UserCredentials credentials = getUserCredentials ();
61
+ if (credentials == null ) {
54
62
return new SimpleMongoDbFactory (mongo (), getDatabaseName ());
55
63
} else {
56
- return new SimpleMongoDbFactory (mongo (), getDatabaseName (), getUserCredentials () );
64
+ return new SimpleMongoDbFactory (mongo (), getDatabaseName (), credentials );
57
65
}
58
66
}
59
67
0 commit comments