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
This commit is contained in:
Oleg Zhurakousky
2018-02-09 10:28:54 -05:00
parent 0332d16c48
commit 0463f7939d
9 changed files with 33 additions and 28 deletions

View File

@@ -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);
}
}

View File

@@ -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");

View File

@@ -15,6 +15,10 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

View File

@@ -17,6 +17,10 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>

View File

@@ -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");

View File

@@ -18,10 +18,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>

View File

@@ -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]),

View File

@@ -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;
/**

View File

@@ -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<String> 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<String> parentArgs = (List<String>) aggregateApplicationBuilderAccessor.getPropertyValue(
"parentArgs");
assertThat(parentArgs).containsExactlyInAnyOrder(argsToVerify.toArray(new String[argsToVerify.size()]));
List<Object> sources = (List<Object>) 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