@@ -56,7 +56,7 @@ public abstract class AbstractCouchbaseConfiguration {
56
56
*
57
57
* @return the list of bootstrap hosts.
58
58
*/
59
- protected abstract List <String > bootstrapHosts ();
59
+ protected abstract List <String > getBootstrapHosts ();
60
60
61
61
/**
62
62
* The name of the bucket to connect to.
@@ -73,39 +73,33 @@ public abstract class AbstractCouchbaseConfiguration {
73
73
protected abstract String getBucketPassword ();
74
74
75
75
/**
76
- * Override this method if you use Couchbase outside of the Spring context.
77
- * If non-null, defines the {@link CouchbaseEnvironment} to use for connection (it is your
78
- * responsibility to shutdown() it).
76
+ * Is the {@link #getEnvironment()} to be destroyed by Spring?
79
77
*
80
- * @return a pre-existing environment managed outside of Spring, or null if instead a managed
81
- * environment is to be used.
78
+ * @return true if Spring should destroy the environment with the context, false otherwise.
82
79
*/
83
- protected CouchbaseEnvironment sharedEnvironment () {
84
- return null ; //assume most of the time we'll create a dedicated one
80
+ protected boolean isEnvironmentManagedBySpring () {
81
+ return true ;
85
82
}
86
83
87
84
/**
88
- * Override this method if you want a customized {@link CouchbaseEnvironment} but only
89
- * use it in the Spring context. This environment will be managed by Spring, which will
90
- * call its shutdown() method upon bean destruction.
85
+ * Override this method if you want a customized {@link CouchbaseEnvironment}.
86
+ * This environment will be managed by Spring, which will call its shutdown()
87
+ * method upon bean destruction, unless you override {@link #isEnvironmentManagedBySpring()}
88
+ * as well to return false.
91
89
*
92
- * @return a customized environment to be managed by Spring , defaults to a {@link DefaultCouchbaseEnvironment}.
90
+ * @return a customized environment, defaults to a {@link DefaultCouchbaseEnvironment}.
93
91
*/
94
- protected CouchbaseEnvironment managedEnvironment () {
92
+ protected CouchbaseEnvironment getEnvironment () {
95
93
return DefaultCouchbaseEnvironment .create ();
96
94
}
97
95
98
96
@ Bean (destroyMethod = "shutdown" , name = BeanNames .COUCHBASE_ENV )
99
- @ Conditional (ConfigurationCondition .class )
100
97
public CouchbaseEnvironment couchbaseEnvironment () {
101
- CouchbaseEnvironment env = sharedEnvironment ();
102
- if (env != null ) {
103
- //the shared environment shouldn't have its shutdown method called when
104
- //the bean is destroyed, it is the responsibility of the user to destroy it.
105
- return new CouchbaseEnvironmentNoShutdownProxy (env );
106
- } else {
107
- return managedEnvironment ();
98
+ CouchbaseEnvironment env = getEnvironment ();
99
+ if (isEnvironmentManagedBySpring ()) {
100
+ return env ;
108
101
}
102
+ return new CouchbaseEnvironmentNoShutdownProxy (env );
109
103
}
110
104
111
105
/**
@@ -115,7 +109,7 @@ public CouchbaseEnvironment couchbaseEnvironment() {
115
109
*/
116
110
@ Bean (destroyMethod = "disconnect" , name = BeanNames .COUCHBASE_CLUSTER )
117
111
public Cluster couchbaseCluster () throws Exception {
118
- return CouchbaseCluster .create (couchbaseEnvironment (), bootstrapHosts ());
112
+ return CouchbaseCluster .create (couchbaseEnvironment (), getBootstrapHosts ());
119
113
}
120
114
121
115
/**
0 commit comments