1
1
/*
2
- * Copyright 2012-2020 the original author or authors.
2
+ * Copyright 2012-2021 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.
28
28
*
29
29
* @author Phillip Webb
30
30
* @author Brian Clozel
31
+ * @author Nguyen Sach
31
32
* @since 1.3.0
32
33
*/
33
34
public enum CloudPlatform {
@@ -131,13 +132,15 @@ private boolean isAutoDetected(EnumerablePropertySource<?> environmentPropertySo
131
132
132
133
};
133
134
135
+ private static final String PROPERTY_NAME = "spring.main.cloud-platform" ;
136
+
134
137
/**
135
138
* Determines if the platform is active (i.e. the application is running in it).
136
139
* @param environment the environment
137
140
* @return if the platform is active.
138
141
*/
139
142
public boolean isActive (Environment environment ) {
140
- return isEnforced (environment ) || isDetected (environment );
143
+ return isEnforced (environment ) || ( isAutoDetectionEnabled ( environment ) && isDetected (environment ) );
141
144
}
142
145
143
146
/**
@@ -148,7 +151,7 @@ public boolean isActive(Environment environment) {
148
151
* @since 2.3.0
149
152
*/
150
153
public boolean isEnforced (Environment environment ) {
151
- String platform = environment .getProperty ("spring.main.cloud-platform" );
154
+ String platform = environment .getProperty (PROPERTY_NAME );
152
155
return name ().equalsIgnoreCase (platform );
153
156
}
154
157
@@ -161,6 +164,16 @@ public boolean isEnforced(Environment environment) {
161
164
*/
162
165
public abstract boolean isDetected (Environment environment );
163
166
167
+ /**
168
+ * Determines if it is enabled that the platform is detected by looking for
169
+ * platform-specific environment variables.
170
+ * @param environment the environment
171
+ * @return if the platform auto-detection is enabled.
172
+ */
173
+ private boolean isAutoDetectionEnabled (Environment environment ) {
174
+ return environment .getProperty (PROPERTY_NAME ) == null ;
175
+ }
176
+
164
177
/**
165
178
* Returns if the platform is behind a load balancer and uses
166
179
* {@literal X-Forwarded-For} headers.
0 commit comments