From f263746420ac8d58e96fc63cb4ec356a03c9c79f Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Sat, 17 Feb 2018 07:42:31 -0500 Subject: [PATCH] GH-1214 Fixed ClassUtils check for Servlet API Resolves #1214 --- .../aggregate/AggregateApplicationBuilder.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/aggregate/AggregateApplicationBuilder.java b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/aggregate/AggregateApplicationBuilder.java index 4e26c430d..cc29d2ec3 100644 --- a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/aggregate/AggregateApplicationBuilder.java +++ b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/aggregate/AggregateApplicationBuilder.java @@ -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]),