|
138 | 138 | * @author Dave Syer
|
139 | 139 | * @author Andy Wilkinson
|
140 | 140 | * @author Christian Dupuis
|
| 141 | + * @author Stephane Nicoll |
141 | 142 | * @see #run(Object, String[])
|
142 | 143 | * @see #run(Object[], String[])
|
143 | 144 | * @see #SpringApplication(Object...)
|
@@ -226,21 +227,12 @@ private void initialize(Object[] sources) {
|
226 | 227 | if (sources != null && sources.length > 0) {
|
227 | 228 | this.sources.addAll(Arrays.asList(sources));
|
228 | 229 | }
|
229 |
| - this.webEnvironment = deduceWebEnvironment(); |
| 230 | + this.webEnvironment = isSpringWebAvailable(); |
230 | 231 | setInitializers((Collection) getSpringFactoriesInstances(ApplicationContextInitializer.class));
|
231 | 232 | setListeners((Collection) getSpringFactoriesInstances(ApplicationListener.class));
|
232 | 233 | this.mainApplicationClass = deduceMainApplicationClass();
|
233 | 234 | }
|
234 | 235 |
|
235 |
| - private boolean deduceWebEnvironment() { |
236 |
| - for (String className : WEB_ENVIRONMENT_CLASSES) { |
237 |
| - if (!ClassUtils.isPresent(className, null)) { |
238 |
| - return false; |
239 |
| - } |
240 |
| - } |
241 |
| - return true; |
242 |
| - } |
243 |
| - |
244 | 236 | private Class<?> deduceMainApplicationClass() {
|
245 | 237 | try {
|
246 | 238 | StackTraceElement[] stackTrace = new RuntimeException().getStackTrace();
|
@@ -872,7 +864,8 @@ public void setResourceLoader(ResourceLoader resourceLoader) {
|
872 | 864 | public void setApplicationContextClass(
|
873 | 865 | Class<? extends ConfigurableApplicationContext> applicationContextClass) {
|
874 | 866 | this.applicationContextClass = applicationContextClass;
|
875 |
| - if (!WebApplicationContext.class.isAssignableFrom(applicationContextClass)) { |
| 867 | + if (isSpringWebAvailable() && !WebApplicationContext.class.isAssignableFrom( |
| 868 | + applicationContextClass)) { |
876 | 869 | this.webEnvironment = false;
|
877 | 870 | }
|
878 | 871 | }
|
@@ -935,6 +928,15 @@ public Set<ApplicationListener<?>> getListeners() {
|
935 | 928 | return asUnmodifiableOrderedSet(this.listeners);
|
936 | 929 | }
|
937 | 930 |
|
| 931 | + private boolean isSpringWebAvailable() { |
| 932 | + for (String className : WEB_ENVIRONMENT_CLASSES) { |
| 933 | + if (!ClassUtils.isPresent(className, null)) { |
| 934 | + return false; |
| 935 | + } |
| 936 | + } |
| 937 | + return true; |
| 938 | + } |
| 939 | + |
938 | 940 | /**
|
939 | 941 | * Static helper that can be used to run a {@link SpringApplication} from the
|
940 | 942 | * specified source using default settings.
|
|
0 commit comments