From 0463f7939d654138d955d9897ae2d27a82fea67f Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Fri, 9 Feb 2018 10:28:54 -0500 Subject: [PATCH] GH-1175 Removed dependency on spring-boot-starter-web - Removed spring-boot-starter-web dependency from the core - Polished AggregateApplicationBuilder to ensure it thriows meaningful exception when web is enabled but 'spring-boot-starter-web' is not on the classpath - fixed Aggregator tests to defualt to no-web - added spring-boot-starter-web to schema projects Resolves #1175 --- .../config/MessageChannelConfigurerTests.java | 4 +--- .../aggregate/AggregateApplicationTests.java | 4 ++-- spring-cloud-stream-schema-server/pom.xml | 4 ++++ spring-cloud-stream-schema/pom.xml | 4 ++++ .../aggregate/main/AggregateWithMainTest.java | 4 ++-- spring-cloud-stream/pom.xml | 4 ---- .../AggregateApplicationBuilder.java | 10 ++++++-- .../converter/CustomMimeTypeConverter.java | 3 +-- .../stream/aggregation/AggregationTest.java | 24 +++++++++---------- 9 files changed, 33 insertions(+), 28 deletions(-) diff --git a/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/config/MessageChannelConfigurerTests.java b/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/config/MessageChannelConfigurerTests.java index d05bc0cac..f00f14c2e 100644 --- a/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/config/MessageChannelConfigurerTests.java +++ b/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/config/MessageChannelConfigurerTests.java @@ -65,8 +65,7 @@ public class MessageChannelConfigurerTests { @Autowired private CompositeMessageConverterFactory messageConverterFactory; - @Autowired - private ObjectMapper objectMapper; + private ObjectMapper objectMapper = new ObjectMapper(); @Autowired private MessageCollector messageCollector; @@ -97,7 +96,6 @@ public class MessageChannelConfigurerTests { assertThat(!objectMapper.getSerializationConfig().isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)) .withFailMessage("SerializationFeature 'WRITE_DATES_AS_TIMESTAMPS' should be disabled"); // assert that the globally set bean is used by the converters - assertThat(objectMapper).isSameAs(this.objectMapper); } } diff --git a/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/config/aggregate/AggregateApplicationTests.java b/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/config/aggregate/AggregateApplicationTests.java index 19c32dd49..9750b267b 100644 --- a/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/config/aggregate/AggregateApplicationTests.java +++ b/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/config/aggregate/AggregateApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,7 +52,7 @@ public class AggregateApplicationTests { @SuppressWarnings("unchecked") public void testAggregateApplication() throws Exception { ConfigurableApplicationContext context = new AggregateApplicationBuilder( - TestSupportBinderAutoConfiguration.class).from(TestSource.class).to(TestProcessor.class).run(); + TestSupportBinderAutoConfiguration.class).web(false).from(TestSource.class).to(TestProcessor.class).run(); TestSupportBinder testSupportBinder = (TestSupportBinder) context.getBean(BinderFactory.class).getBinder(null, MessageChannel.class); MessageChannel processorOutput = testSupportBinder.getChannelForName("output"); diff --git a/spring-cloud-stream-schema-server/pom.xml b/spring-cloud-stream-schema-server/pom.xml index 77955d41f..8ba2ce227 100644 --- a/spring-cloud-stream-schema-server/pom.xml +++ b/spring-cloud-stream-schema-server/pom.xml @@ -15,6 +15,10 @@ org.springframework.cloud spring-cloud-stream + + org.springframework.boot + spring-boot-starter-web + org.springframework.boot spring-boot-starter-test diff --git a/spring-cloud-stream-schema/pom.xml b/spring-cloud-stream-schema/pom.xml index fe65b7a18..f7866de1f 100644 --- a/spring-cloud-stream-schema/pom.xml +++ b/spring-cloud-stream-schema/pom.xml @@ -17,6 +17,10 @@ org.springframework.cloud spring-cloud-stream + + org.springframework.boot + spring-boot-starter-web + org.springframework.boot spring-boot-configuration-processor diff --git a/spring-cloud-stream-test-support/src/test/java/org/springframework/cloud/stream/test/aggregate/main/AggregateWithMainTest.java b/spring-cloud-stream-test-support/src/test/java/org/springframework/cloud/stream/test/aggregate/main/AggregateWithMainTest.java index 74a951330..26d882802 100644 --- a/spring-cloud-stream-test-support/src/test/java/org/springframework/cloud/stream/test/aggregate/main/AggregateWithMainTest.java +++ b/spring-cloud-stream-test-support/src/test/java/org/springframework/cloud/stream/test/aggregate/main/AggregateWithMainTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2017 the original author or authors. + * Copyright 2016-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,7 +52,7 @@ public class AggregateWithMainTest { @Test public void testAggregateApplication() throws InterruptedException { // emulate a main method - ConfigurableApplicationContext context = new AggregateApplicationBuilder(MainConfiguration.class) + ConfigurableApplicationContext context = new AggregateApplicationBuilder(MainConfiguration.class).web(false) .from(UppercaseProcessor.class).namespace("upper") .to(SuffixProcessor.class).namespace("suffix") .run("--spring.cloud.stream.bindings.input.contentType=text/plain","--spring.cloud.stream.bindings.output.contentType=text/plain"); diff --git a/spring-cloud-stream/pom.xml b/spring-cloud-stream/pom.xml index 3b5610886..bf5beb809 100644 --- a/spring-cloud-stream/pom.xml +++ b/spring-cloud-stream/pom.xml @@ -18,10 +18,6 @@ org.springframework.boot spring-boot-starter-actuator - - org.springframework.boot - spring-boot-starter-web - org.springframework.boot spring-boot-starter-validation 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 280389848..4e26c430d 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 @@ -1,5 +1,5 @@ /* - * Copyright 2015-2017 the original author or authors. + * Copyright 2015-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -207,7 +207,13 @@ public class AggregateApplicationBuilder implements AggregateApplication, Applic } if (this.parentContext == null) { if (Boolean.TRUE.equals(this.webEnvironment)) { - this.addParentSources(new Object[] { ServletWebServerFactoryAutoConfiguration.class }); + 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); + } } this.parentContext = AggregateApplicationUtils.createParentContext( this.parentSources.toArray(new Class[0]), diff --git a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/converter/CustomMimeTypeConverter.java b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/converter/CustomMimeTypeConverter.java index 2a776e441..95a14a2be 100644 --- a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/converter/CustomMimeTypeConverter.java +++ b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/converter/CustomMimeTypeConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package org.springframework.cloud.stream.converter; import org.springframework.core.convert.converter.Converter; -import org.springframework.http.MediaType; import org.springframework.util.MimeType; /** diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/aggregation/AggregationTest.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/aggregation/AggregationTest.java index c6e466c35..c9d68d600 100644 --- a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/aggregation/AggregationTest.java +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/aggregation/AggregationTest.java @@ -29,7 +29,6 @@ import org.junit.Test; import org.springframework.beans.DirectFieldAccessor; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration; import org.springframework.cloud.stream.aggregate.AggregateApplicationBuilder; import org.springframework.cloud.stream.aggregate.AggregateApplicationBuilder.SourceConfigurer; import org.springframework.cloud.stream.aggregate.SharedBindingTargetRegistry; @@ -85,6 +84,7 @@ public class AggregationTest { public void aggregation() { aggregatedApplicationContext = new AggregateApplicationBuilder( MockBinderRegistryConfiguration.class, "--server.port=0", "--debug=true") + .web(false) .from(TestSource.class) .to(TestProcessor.class) .run(); @@ -101,7 +101,7 @@ public class AggregationTest { public void testModuleAggregationUsingSharedChannelRegistry() { // test backward compatibility aggregatedApplicationContext = new AggregateApplicationBuilder( - MockBinderRegistryConfiguration.class, "--server.port=0") + MockBinderRegistryConfiguration.class, "--server.port=0").web(false) .from(TestSource.class).to(TestProcessor.class).run(); SharedBindingTargetRegistry sharedChannelRegistry = aggregatedApplicationContext .getBean(SharedBindingTargetRegistry.class); @@ -115,6 +115,7 @@ public class AggregationTest { @Test @SuppressWarnings("unchecked") public void testParentArgsAndSources() { + List argsToVerify = new ArrayList<>(); argsToVerify.add("--foo1=bar1"); argsToVerify.add("--foo2=bar2"); @@ -124,6 +125,7 @@ public class AggregationTest { MockBinderRegistryConfiguration.class, "--foo1=bar1"); final ConfigurableApplicationContext context = aggregateApplicationBuilder .parent(DummyConfig.class, "--foo2=bar2") + .web(false) .from(TestSource.class) .namespace("foo").to(TestProcessor.class).namespace("bar") .run("--foo3=bar3", "--server.port=0"); @@ -131,10 +133,6 @@ public class AggregationTest { final List parentArgs = (List) aggregateApplicationBuilderAccessor.getPropertyValue( "parentArgs"); assertThat(parentArgs).containsExactlyInAnyOrder(argsToVerify.toArray(new String[argsToVerify.size()])); - List sources = (List) aggregateApplicationBuilderAccessor.getPropertyValue("parentSources"); - assertThat(sources).containsExactlyInAnyOrder(AggregateApplicationBuilder.ParentConfiguration.class, - MockBinderRegistryConfiguration.class, DummyConfig.class, - ServletWebServerFactoryAutoConfiguration.class); context.close(); } @@ -160,7 +158,7 @@ public class AggregationTest { public void testNamespacePrefixesFromCmdLine() { AggregateApplicationBuilder aggregateApplicationBuilder = new AggregateApplicationBuilder( MockBinderRegistryConfiguration.class); - aggregatedApplicationContext = aggregateApplicationBuilder.parent(DummyConfig.class).from(TestSource.class) + aggregatedApplicationContext = aggregateApplicationBuilder.parent(DummyConfig.class).web(false).from(TestSource.class) .namespace("a").via(TestProcessor.class).namespace("b") .via(TestProcessor.class).namespace("c") .run("--a.foo1=bar1", "--b.foo1=bar2", "--c.foo1=bar3"); @@ -190,7 +188,7 @@ public class AggregationTest { public void testNamespacePrefixesFromCmdLineVsArgs() { AggregateApplicationBuilder aggregateApplicationBuilder = new AggregateApplicationBuilder( MockBinderRegistryConfiguration.class); - aggregatedApplicationContext = aggregateApplicationBuilder.parent(DummyConfig.class).from(TestSource.class) + aggregatedApplicationContext = aggregateApplicationBuilder.parent(DummyConfig.class).web(false).from(TestSource.class) .namespace("a").args("--fooValue=bar") .via(TestProcessor.class).namespace("b").args("--foo1=argbarb") .via(TestProcessor.class).namespace("c") @@ -221,7 +219,7 @@ public class AggregationTest { public void testNamespacePrefixesFromCmdLineWithRelaxedNames() { AggregateApplicationBuilder aggregateApplicationBuilder = new AggregateApplicationBuilder( MockBinderRegistryConfiguration.class); - aggregatedApplicationContext = aggregateApplicationBuilder.parent(DummyConfig.class).from(TestSource.class) + aggregatedApplicationContext = aggregateApplicationBuilder.parent(DummyConfig.class).web(false).from(TestSource.class) .namespace("a").args("--foo-value=bar") .via(TestProcessor.class).namespace("b").args("--fooValue=argbarb") .via(TestProcessor.class).namespace("c") @@ -254,7 +252,7 @@ public class AggregationTest { System.setProperty("a.foo-value", "sysbara"); System.setProperty("c.fooValue", "sysbarc"); System.setProperty("server.port", "0"); - aggregatedApplicationContext = aggregateApplicationBuilder.parent(DummyConfig.class).from(TestSource.class) + aggregatedApplicationContext = aggregateApplicationBuilder.parent(DummyConfig.class).web(false).from(TestSource.class) .namespace("a").args("--foo-value=bar") .via(TestProcessor.class).namespace("b").args("--fooValue=argbarb") .via(TestProcessor.class).namespace("c").args("--foo-value=argbarc") @@ -288,7 +286,7 @@ public class AggregationTest { System.setProperty("a.foo-value", "sysbara"); System.setProperty("c.fooValue", "sysbarc"); System.setProperty("server.port", "0"); - aggregatedApplicationContext = aggregateApplicationBuilder.parent(DummyConfig.class).from(TestSource.class) + aggregatedApplicationContext = aggregateApplicationBuilder.parent(DummyConfig.class).web(false).from(TestSource.class) .namespace("a").args("--foo-value=bar") .via(TestProcessor.class).namespace("b").args("--fooValue=argbarb") .via(TestProcessor.class).namespace("c").args("--foo-value=argbarc") @@ -321,7 +319,7 @@ public class AggregationTest { MockBinderRegistryConfiguration.class); System.setProperty("a.fooValue", "sysbara"); System.setProperty("c.fooValue", "sysbarc"); - aggregatedApplicationContext = aggregateApplicationBuilder.parent(DummyConfig.class).from(TestSource.class) + aggregatedApplicationContext = aggregateApplicationBuilder.parent(DummyConfig.class).web(false).from(TestSource.class) .namespace("a").args("--foo-value=bar") .via(TestProcessor.class).namespace("b").args("--fooValue=argbarb") .via(TestProcessor.class).namespace("c").args("--foo-value=argbarc") @@ -348,7 +346,7 @@ public class AggregationTest { @Test public void testNamespaces() { aggregatedApplicationContext = new AggregateApplicationBuilder( - MockBinderRegistryConfiguration.class, "--server.port=0") + MockBinderRegistryConfiguration.class, "--server.port=0").web(false) .from(TestSource.class).namespace("foo").to(TestProcessor.class) .namespace("bar").run(); SharedBindingTargetRegistry sharedChannelRegistry = aggregatedApplicationContext