From 1ece7ab803c82f3a644d7adb07547a09f06c39fd Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Thu, 23 Oct 2014 05:26:05 -0700 Subject: [PATCH] Make executable jar work better as an embeddable I think it's a good idea to provide an executable jar (good getting started experience), but it wasn't working very well. The biggest problem was the missing main() method, but that was easy to fix. More interestingly I have changed the default config name to "configserver" so "configserver.yml" is loaded to set the default config for the standalone jar, and this file can easily be ignored in a customized server. Fixes gh-17 --- spring-cloud-config-server/pom.xml | 2 +- .../cloud/config/server/ConfigServerApplication.java | 6 ++++++ .../main/resources/{application.yml => configserver.yml} | 0 .../cloud/config/server/ApplicationTests.java | 4 +++- .../SpringApplicationEnvironmentRepositoryTests.java | 8 ++++---- .../resources/configserver-test.yml} | 0 6 files changed, 14 insertions(+), 6 deletions(-) rename spring-cloud-config-server/src/main/resources/{application.yml => configserver.yml} (100%) rename spring-cloud-config-server/src/{main/resources/application-test.yml => test/resources/configserver-test.yml} (100%) diff --git a/spring-cloud-config-server/pom.xml b/spring-cloud-config-server/pom.xml index e6afe382..4e19d220 100644 --- a/spring-cloud-config-server/pom.xml +++ b/spring-cloud-config-server/pom.xml @@ -51,7 +51,7 @@ UTF-8 ${project.version} - org.springframework.cloud.config.server.Application + org.springframework.cloud.config.server.ConfigServerApplication 1.7 diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/ConfigServerApplication.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/ConfigServerApplication.java index ea6ef56b..9fc9e486 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/ConfigServerApplication.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/ConfigServerApplication.java @@ -1,6 +1,7 @@ package org.springframework.cloud.config.server; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.context.annotation.Configuration; @Configuration @@ -8,4 +9,9 @@ import org.springframework.context.annotation.Configuration; @EnableConfigServer public class ConfigServerApplication { + public static void main(String[] args) { + new SpringApplicationBuilder(ConfigServerApplication.class).properties( + "spring.config.name=configserver").run(args); + } + } diff --git a/spring-cloud-config-server/src/main/resources/application.yml b/spring-cloud-config-server/src/main/resources/configserver.yml similarity index 100% rename from spring-cloud-config-server/src/main/resources/application.yml rename to spring-cloud-config-server/src/main/resources/configserver.yml diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ApplicationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ApplicationTests.java index 936e1d5f..bf548d04 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ApplicationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/ApplicationTests.java @@ -9,13 +9,15 @@ import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; import org.springframework.cloud.config.Environment; +import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = ConfigServerApplication.class) -@IntegrationTest("server.port:0") +@IntegrationTest({"server.port:0", "spring.config.name:configserver"}) @WebAppConfiguration +@ActiveProfiles("test") public class ApplicationTests { @Value("${local.server.port}") diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/SpringApplicationEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/SpringApplicationEnvironmentRepositoryTests.java index ca2a2c84..25043488 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/SpringApplicationEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/SpringApplicationEnvironmentRepositoryTests.java @@ -32,28 +32,28 @@ public class SpringApplicationEnvironmentRepositoryTests { @Test public void vanilla() { Environment environment = repository.findOne("foo", "development", "master"); - assertEquals(3, environment.getPropertySources().size()); + assertEquals(2, environment.getPropertySources().size()); } @Test public void ignoresExistingProfile() { System.setProperty("spring.profiles.active", "cloud"); Environment environment = repository.findOne("foo", "main", "master"); - assertEquals(2, environment.getPropertySources().size()); + assertEquals(1, environment.getPropertySources().size()); } @Test public void prefixed() { repository.setSearchLocations("classpath:/test"); Environment environment = repository.findOne("foo", "development", "master"); - assertEquals(4, environment.getPropertySources().size()); + assertEquals(3, environment.getPropertySources().size()); } @Test public void prefixedWithFile() { repository.setSearchLocations("file:./src/test/resources/test"); Environment environment = repository.findOne("foo", "development", "master"); - assertEquals(4, environment.getPropertySources().size()); + assertEquals(3, environment.getPropertySources().size()); } } diff --git a/spring-cloud-config-server/src/main/resources/application-test.yml b/spring-cloud-config-server/src/test/resources/configserver-test.yml similarity index 100% rename from spring-cloud-config-server/src/main/resources/application-test.yml rename to spring-cloud-config-server/src/test/resources/configserver-test.yml