GH-1214 Fixed ClassUtils check for Servlet API

Resolves #1214
This commit is contained in:
Oleg Zhurakousky
2018-02-17 07:42:31 -05:00
parent 746dbc1bd3
commit f263746420

View File

@@ -45,6 +45,7 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
/**
@@ -207,13 +208,10 @@ public class AggregateApplicationBuilder implements AggregateApplication, Applic
}
if (this.parentContext == null) {
if (Boolean.TRUE.equals(this.webEnvironment)) {
try {
Class.forName("javax.servlet.ServletRequest");
this.addParentSources(new Object[] { ServletWebServerFactoryAutoConfiguration.class });
} catch (Exception e) {
throw new IllegalStateException("'webEnvironment' is set to 'true' but 'javax.servlet.*' does not appear to be available in the classpath. "
+ "Consider adding `org.springframework.boot:spring-boot-starter-web", e);
}
Assert.isTrue(ClassUtils.isPresent("javax.servlet.ServletRequest", ClassUtils.getDefaultClassLoader()),
"'webEnvironment' is set to 'true' but 'javax.servlet.*' does not appear to be available in "
+ "the classpath. Consider adding `org.springframework.boot:spring-boot-starter-web");
this.addParentSources(new Object[] { ServletWebServerFactoryAutoConfiguration.class });
}
this.parentContext = AggregateApplicationUtils.createParentContext(
this.parentSources.toArray(new Class<?>[0]),