From 66b7d8dbe4046327cf8084f12b691b9c2fac8229 Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Fri, 15 Jun 2018 11:12:15 -0400 Subject: [PATCH] Prevent SpringBootApplication starting to overlap with user defined Application. Fixes #1391 Resolves #1393 --- .../schema/server/SchemaRegistryServerApplication.java | 10 ++++++---- .../{application.yml => schemaregistryserver.yml} | 0 .../schema/server/SchemaRegistryServerAvroTests.java | 6 +++++- .../avro/AvroMessageConverterSerializationTests.java | 7 ++++--- .../AvroSchemaRegistryClientMessageConverterTests.java | 7 +++++-- 5 files changed, 20 insertions(+), 10 deletions(-) rename spring-cloud-stream-schema-server/src/main/resources/{application.yml => schemaregistryserver.yml} (100%) diff --git a/spring-cloud-stream-schema-server/src/main/java/org/springframework/cloud/stream/schema/server/SchemaRegistryServerApplication.java b/spring-cloud-stream-schema-server/src/main/java/org/springframework/cloud/stream/schema/server/SchemaRegistryServerApplication.java index 76b084281..8e9b44b29 100644 --- a/spring-cloud-stream-schema-server/src/main/java/org/springframework/cloud/stream/schema/server/SchemaRegistryServerApplication.java +++ b/spring-cloud-stream-schema-server/src/main/java/org/springframework/cloud/stream/schema/server/SchemaRegistryServerApplication.java @@ -16,16 +16,18 @@ package org.springframework.cloud.stream.schema.server; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; /** * @author Vinicius Carvalho + * @author Guilherme Blanco */ -@SpringBootApplication +@EnableAutoConfiguration @EnableSchemaRegistryServer public class SchemaRegistryServerApplication { public static void main(String[] args) { - SpringApplication.run(SchemaRegistryServerApplication.class, args); + new SpringApplicationBuilder(SchemaRegistryServerApplication.class) + .properties("spring.config.name=schemaregistryserver").run(args); } } diff --git a/spring-cloud-stream-schema-server/src/main/resources/application.yml b/spring-cloud-stream-schema-server/src/main/resources/schemaregistryserver.yml similarity index 100% rename from spring-cloud-stream-schema-server/src/main/resources/application.yml rename to spring-cloud-stream-schema-server/src/main/resources/schemaregistryserver.yml diff --git a/spring-cloud-stream-schema-server/src/test/java/org/springframework/cloud/stream/schema/server/SchemaRegistryServerAvroTests.java b/spring-cloud-stream-schema-server/src/test/java/org/springframework/cloud/stream/schema/server/SchemaRegistryServerAvroTests.java index c91826c53..ea7e99d6f 100644 --- a/spring-cloud-stream-schema-server/src/test/java/org/springframework/cloud/stream/schema/server/SchemaRegistryServerAvroTests.java +++ b/spring-cloud-stream-schema-server/src/test/java/org/springframework/cloud/stream/schema/server/SchemaRegistryServerAvroTests.java @@ -44,7 +44,11 @@ import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER * @author Ilayaperumal Gopinathan */ @RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +@SpringBootTest( + classes = SchemaRegistryServerApplication.class, + properties = {"spring.config.name:schemaregistryserver"}, + webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT +) @DirtiesContext(classMode = AFTER_EACH_TEST_METHOD) public class SchemaRegistryServerAvroTests { diff --git a/spring-cloud-stream-schema/src/test/java/org/springframework/cloud/schema/avro/AvroMessageConverterSerializationTests.java b/spring-cloud-stream-schema/src/test/java/org/springframework/cloud/schema/avro/AvroMessageConverterSerializationTests.java index a75814b21..1cab121db 100644 --- a/spring-cloud-stream-schema/src/test/java/org/springframework/cloud/schema/avro/AvroMessageConverterSerializationTests.java +++ b/spring-cloud-stream-schema/src/test/java/org/springframework/cloud/schema/avro/AvroMessageConverterSerializationTests.java @@ -36,7 +36,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.springframework.boot.SpringApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cache.support.NoOpCacheManager; import org.springframework.cloud.stream.binder.BinderHeaders; import org.springframework.cloud.stream.schema.SchemaReference; @@ -67,8 +67,9 @@ public class AvroMessageConverterSerializationTests { @Before public void setup() { - schemaRegistryServerContext = SpringApplication - .run(SchemaRegistryServerApplication.class); + schemaRegistryServerContext = new SpringApplicationBuilder(SchemaRegistryServerApplication.class) + .properties("spring.config.name=schemaregistryserver") + .run(); } @After diff --git a/spring-cloud-stream-schema/src/test/java/org/springframework/cloud/schema/avro/AvroSchemaRegistryClientMessageConverterTests.java b/spring-cloud-stream-schema/src/test/java/org/springframework/cloud/schema/avro/AvroSchemaRegistryClientMessageConverterTests.java index d89b7767e..da5adb9ca 100644 --- a/spring-cloud-stream-schema/src/test/java/org/springframework/cloud/schema/avro/AvroSchemaRegistryClientMessageConverterTests.java +++ b/spring-cloud-stream-schema/src/test/java/org/springframework/cloud/schema/avro/AvroSchemaRegistryClientMessageConverterTests.java @@ -26,6 +26,7 @@ import org.junit.Test; import org.springframework.beans.DirectFieldAccessor; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cache.support.NoOpCacheManager; import org.springframework.cloud.stream.annotation.EnableBinding; import org.springframework.cloud.stream.annotation.StreamListener; @@ -57,8 +58,10 @@ public class AvroSchemaRegistryClientMessageConverterTests { @Test public void testSendMessage() throws Exception { - ConfigurableApplicationContext schemaRegistryServerContext = SpringApplication.run( - SchemaRegistryServerApplication.class); + ConfigurableApplicationContext schemaRegistryServerContext = + new SpringApplicationBuilder(SchemaRegistryServerApplication.class) + .properties("spring.config.name=schemaregistryserver") + .run(); ConfigurableApplicationContext sourceContext = SpringApplication.run(AvroSourceApplication.class, "--server.port=0",